Skip to content

Commit

Permalink
fix: charts
Browse files Browse the repository at this point in the history
  • Loading branch information
Friedjof committed Oct 22, 2024
1 parent ca0b016 commit 4affdd7
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions analytics/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,11 @@ def map_weekday_hour_diagram() -> str:
heatmap_data = [[0 for _ in range(24)] for _ in range(7)] # 7 days, 24 hours

for entry in weekday_hour_counts:
heatmap_data[entry['weekday'] - 1][entry['hour']] = entry[
'total'] # Weekday is 1-based (1=Sunday, 7=Saturday)
heatmap_data[entry['weekday'] - 1][entry['hour']] = entry['total'] # Weekday is 1-based (1=Sunday, 7=Saturday)

# Create the heatmap
fig, ax = plt.subplots(figsize=(12, 7))
cax = ax.matshow(heatmap_data, cmap='YlGnBu')
cax = ax.matshow(heatmap_data, cmap='summer')

# Set axis labels
ax.set_xticks(range(24))
Expand All @@ -149,6 +148,11 @@ def map_weekday_hour_diagram() -> str:
# Add color bar
fig.colorbar(cax)

# Add text annotations
for i in range(7):
for j in range(24):
ax.text(j, i, str(heatmap_data[i][j]), va='center', ha='center', color='black')

ax.set_xlabel('Hour of the Day')
ax.set_ylabel('Weekday')
ax.set_title('Average Number of Running Machines per Weekday and Hour')
Expand Down Expand Up @@ -197,6 +201,9 @@ def last_3_weeks_of_running_machines() -> str:
plt.xticks(rotation=45)
plt.tight_layout()

# Set date format on x-axis
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d (%a)'))

buf = io.BytesIO()
plt.savefig(buf, format='png')
buf.seek(0)
Expand Down Expand Up @@ -254,7 +261,7 @@ def last_3_weeks_of_machine_status() -> str:
plt.tight_layout()

# Set date format on x-axis
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d (%a)'))

# Save the plot to a buffer
buf = io.BytesIO()
Expand Down Expand Up @@ -285,13 +292,14 @@ def used_machines_per_type_and_building() -> str:

# Create the heatmap
fig, ax = plt.subplots()
heatmap_data = [[data[building][machine_number] for machine_number in machine_numbers] for building in buildings]
heatmap_data = [[data[building][machine_number] for machine_number in machine_numbers] for building in
buildings]

# if Invalid shape (0,) for image data
if len(heatmap_data) == 0:
heatmap_data = [[0]]

cax = ax.matshow(heatmap_data, cmap='YlGnBu')
cax = ax.matshow(heatmap_data, cmap='summer')

# Set axis labels
ax.set_xticks(range(len(machine_numbers)))
Expand All @@ -302,6 +310,11 @@ def used_machines_per_type_and_building() -> str:
# Add color bar
fig.colorbar(cax)

# Add text annotations
for i in range(len(buildings)):
for j in range(len(machine_numbers)):
ax.text(j, i, str(heatmap_data[i][j]), va='center', ha='center', color='black')

ax.set_xlabel('Machine Number')
ax.set_ylabel('Building')
ax.set_title('Used Machines per Number and Building')
Expand Down

0 comments on commit 4affdd7

Please sign in to comment.