Skip to content

Commit

Permalink
fix mk presence to handle different mk site ids
Browse files Browse the repository at this point in the history
  • Loading branch information
OriHoch committed Aug 14, 2023
1 parent c11cb14 commit 0a37a9c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
6 changes: 6 additions & 0 deletions members/knesset.source-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,17 @@ presence:
dependencies:
- pipeline: ./members/mk_individual
- datapackage: data/members/mk_individual/datapackage.json
- pipeline: ./members/kns_mksitecode
- datapackage: data/members/kns_mksitecode/datapackage.json
pipeline:
- run: load_resource
parameters:
url: ../data/members/mk_individual/datapackage.json
resource: mk_individual
- run: load_resource
parameters:
url: ../data/members/kns_mksitecode/datapackage.json
resource: kns_mksitecode
- run: read_presence
parameters:
# old presence data from oknesset
Expand Down
24 changes: 14 additions & 10 deletions members/read_presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@
aggregations = {"stats": {}}


mk_individual = {row["mk_individual_id"]: row for row in list(resources)[0]}
resources_list = list(resources)
mk_individual = {row["mk_individual_id"]: row for row in resources_list[0]}
site_id_to_kns_id = {row["SiteId"]: row["KnsID"] for row in resources_list[1]}


def flush_day(current_day):
mk_ids_hours = current_day.get("mk_ids_hours", {})
for mk_id, hours in mk_ids_hours.items():
if mk_id in mk_individual:
yield {"mk_id": mk_id,
"mk_name": mk_individual[mk_id]["mk_individual_first_name"] + " " + mk_individual[mk_id]["mk_individual_name"],
"date": datetime.date(current_day["year"], current_day["month"], current_day["day"]),
"year": current_day["year"],
"month": current_day["month"],
"day": current_day["day"],
"year_week_number": ((datetime.date(current_day["year"], current_day["month"], current_day["day"]) - datetime.date(current_day["year"], 1, 1)).days // 7) + 1,
"total_attended_hours": len(hours)}
if mk_id not in mk_individual:
mk_id = site_id_to_kns_id.get(mk_id)
assert mk_id in mk_individual, f"mk_id {mk_id} not found"
yield {"mk_id": mk_id,
"mk_name": mk_individual[mk_id]["mk_individual_first_name"] + " " + mk_individual[mk_id]["mk_individual_name"],
"date": datetime.date(current_day["year"], current_day["month"], current_day["day"]),
"year": current_day["year"],
"month": current_day["month"],
"day": current_day["day"],
"year_week_number": ((datetime.date(current_day["year"], current_day["month"], current_day["day"]) - datetime.date(current_day["year"], 1, 1)).days // 7) + 1,
"total_attended_hours": len(hours)}


def get_presence_lines():
Expand Down

0 comments on commit 0a37a9c

Please sign in to comment.