Skip to content

Commit

Permalink
feat: break down time allocated in email
Browse files Browse the repository at this point in the history
  • Loading branch information
jashan-lco committed Dec 18, 2024
1 parent 06dc286 commit 3512636
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
8 changes: 5 additions & 3 deletions observation_portal/sciapplications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,15 +421,17 @@ def send_review_accepted_or_rejected_email_to_submitter(self):
semester_start = self.science_application.call.semester.start.strftime("%B %d, %Y")
semester_end = self.science_application.call.semester.end.strftime("%B %d, %Y")

time_by_instrument_type = defaultdict(int)
time_by_instrument_type = defaultdict(lambda: defaultdict(int))

for tr in self.science_application.timerequest_set.filter(approved=True):
instrument_types = frozenset(x.display for x in tr.instrument_types.all())

time_by_instrument_type[instrument_types] += tr.total_requested_time
time_by_instrument_type[instrument_types]["std"] += tr.std_time
time_by_instrument_type[instrument_types]["tc"] += tr.tc_time
time_by_instrument_type[instrument_types]["rr"] += tr.rr_time

instrument_allocations = [
{"name": ", ".join(sorted(k)), "value": v} for k, v in time_by_instrument_type.items()
{"name": ", ".join(sorted(k)), **v} for k, v in time_by_instrument_type.items()
]

message = render_to_string(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@
<table>
<caption>Allocation (hours)</caption>
<thead>
<tr>
{% for x in instrument_allocations %}
<th>{{ x.name }}</th>
{% endfor %}
</tr>
<tr>Instrument</tr>
<tr>Queue</tr>
<tr>TC</tr>
<tr>RR</tr>
</thead>
<tbody>
<tr>
{% for x in instrument_allocations %}
<td>{{ x.value }}</td>
<tr>
<td>{{ x.name }}</td>
<td>{{ x.std }}</td>
<td>{{ x.tc }}</td>
<td>{{ x.rr }}</td>
</tr>
{% endfor %}
</tr>
</tbody>
</table>

Expand Down

0 comments on commit 3512636

Please sign in to comment.