Skip to content

Commit

Permalink
Fix aggregate table tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jdddog committed Jul 21, 2023
1 parent 8b85186 commit 6a4de72
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 39 deletions.
70 changes: 39 additions & 31 deletions academic_observatory_workflows/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,7 @@ def make_aggregate_table(agg: str, dataset: ObservatoryDataset) -> List[Dict]:
"hybrid": at.hybrid,
"bronze": at.bronze,
"green_only": at.green_only,
"black": at.black,
# COKI Open Access Types
"open": oa_coki.open,
"closed": oa_coki.closed,
Expand Down Expand Up @@ -1752,6 +1753,7 @@ def make_aggregate_table(agg: str, dataset: ObservatoryDataset) -> List[Dict]:
"hybrid": "sum",
"bronze": "sum",
"green_only": "sum",
"black": "sum",
# COKI OA types
"open": "sum",
"closed": "sum",
Expand Down Expand Up @@ -1787,6 +1789,7 @@ def make_aggregate_table(agg: str, dataset: ObservatoryDataset) -> List[Dict]:
hybrid = row["hybrid"]
bronze = row["bronze"]
green_only = row["green_only"]
black = row["black"]

# COKI access types
open = row["open"]
Expand Down Expand Up @@ -1841,39 +1844,44 @@ def make_aggregate_table(agg: str, dataset: ObservatoryDataset) -> List[Dict]:
"subregion": row["subregion"],
"coordinates": row["coordinates"],
"total_outputs": total_outputs,
"access_types": {
"oa": {"total_outputs": oa, "percent": calc_percent(oa, total_outputs)},
"green": {"total_outputs": green, "percent": calc_percent(green, total_outputs)},
"gold": {"total_outputs": gold, "percent": calc_percent(gold, total_outputs)},
"gold_doaj": {"total_outputs": gold_doaj, "percent": calc_percent(gold_doaj, total_outputs)},
"hybrid": {"total_outputs": hybrid, "percent": calc_percent(hybrid, total_outputs)},
"bronze": {"total_outputs": bronze, "percent": calc_percent(bronze, total_outputs)},
"green_only": {"total_outputs": green_only, "percent": calc_percent(green_only, total_outputs)},
},
"oa_coki": {
"open": {"total": open, "percent": calc_percent(open, total_outputs)},
"closed": {"total": closed, "percent": calc_percent(closed, total_outputs)},
"publisher": {"total": publisher, "percent": calc_percent(publisher, total_outputs)},
"other_platform": {"total": other_platform, "percent": calc_percent(other_platform, total_outputs)},
"publisher_only": {"total": publisher_only, "percent": calc_percent(publisher_only, total_outputs)},
"both": {"total": both, "percent": calc_percent(both, total_outputs)},
"other_platform_only": {"total": other_platform_only, "percent": calc_percent(other_platform_only, total_outputs)},
"publisher_categories": {
"oa_journal": {"total": publisher_categories_oa_journal, "percent": calc_percent(publisher_categories_oa_journal, publisher)},
"hybrid": {"total": publisher_categories_hybrid, "percent": calc_percent(publisher_categories_hybrid, publisher)},
"no_guarantees": {"total": publisher_categories_no_guarantees, "percent": calc_percent(publisher_categories_no_guarantees, publisher)}
},
"other_platform_categories": {
"preprint": {"total": publisher_categories_preprint, "percent": calc_percent(publisher_categories_preprint, other_platform)},
"domain": {"total": publisher_categories_domain, "percent": calc_percent(publisher_categories_domain, other_platform)},
"institution": {"total": publisher_categories_institution, "percent": calc_percent(publisher_categories_institution, other_platform)},
"public": {"total": publisher_categories_public, "percent": calc_percent(publisher_categories_public, other_platform)},
"aggregator": {"total": publisher_categories_aggregator, "percent": calc_percent(publisher_categories_aggregator, other_platform)},
"other_internet": {"total": publisher_categories_other_internet, "percent": calc_percent(publisher_categories_other_internet, other_platform)},
"unknown": {"total": publisher_categories_unknown, "percent": calc_percent(publisher_categories_unknown, other_platform)},
"coki": {
"oa": {
"color": {
"oa": {"total_outputs": oa, "percent": calc_percent(oa, total_outputs)},
"green": {"total_outputs": green, "percent": calc_percent(green, total_outputs)},
"gold": {"total_outputs": gold, "percent": calc_percent(gold, total_outputs)},
"gold_doaj": {"total_outputs": gold_doaj, "percent": calc_percent(gold_doaj, total_outputs)},
"hybrid": {"total_outputs": hybrid, "percent": calc_percent(hybrid, total_outputs)},
"bronze": {"total_outputs": bronze, "percent": calc_percent(bronze, total_outputs)},
"green_only": {"total_outputs": green_only, "percent": calc_percent(green_only, total_outputs)},
"black": {"total_outputs": black, "percent": calc_percent(black, total_outputs)},
},
"coki": {
"open": {"total": open, "percent": calc_percent(open, total_outputs)},
"closed": {"total": closed, "percent": calc_percent(closed, total_outputs)},
"publisher": {"total": publisher, "percent": calc_percent(publisher, total_outputs)},
"other_platform": {"total": other_platform, "percent": calc_percent(other_platform, total_outputs)},
"publisher_only": {"total": publisher_only, "percent": calc_percent(publisher_only, total_outputs)},
"both": {"total": both, "percent": calc_percent(both, total_outputs)},
"other_platform_only": {"total": other_platform_only, "percent": calc_percent(other_platform_only, total_outputs)},
"publisher_categories": {
"oa_journal": {"total": publisher_categories_oa_journal, "percent": calc_percent(publisher_categories_oa_journal, publisher)},
"hybrid": {"total": publisher_categories_hybrid, "percent": calc_percent(publisher_categories_hybrid, publisher)},
"no_guarantees": {"total": publisher_categories_no_guarantees, "percent": calc_percent(publisher_categories_no_guarantees, publisher)}
},
"other_platform_categories": {
"preprint": {"total": publisher_categories_preprint, "percent": calc_percent(publisher_categories_preprint, other_platform)},
"domain": {"total": publisher_categories_domain, "percent": calc_percent(publisher_categories_domain, other_platform)},
"institution": {"total": publisher_categories_institution, "percent": calc_percent(publisher_categories_institution, other_platform)},
"public": {"total": publisher_categories_public, "percent": calc_percent(publisher_categories_public, other_platform)},
"aggregator": {"total": publisher_categories_aggregator, "percent": calc_percent(publisher_categories_aggregator, other_platform)},
"other_internet": {"total": publisher_categories_other_internet, "percent": calc_percent(publisher_categories_other_internet, other_platform)},
"unknown": {"total": publisher_categories_unknown, "percent": calc_percent(publisher_categories_unknown, other_platform)},
},
}
},
"repositories": repositories
},
"repositories": repositories,
"citations": {},
"output_types": [],
"disciplines": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,23 +605,24 @@ def assert_aggregate(self, expected: List[Dict], actual: List[Dict]):
"region",
"subregion",
"total_outputs",
"repositories",
]:
self.assertEqual(expected_item[key], actual_item[key])

# Access types
expected_coki = expected_item["coki"]
actual_coki = actual_item["coki"]
self.assert_sub_fields(
expected_item,
actual_item,
"access_types",
["oa", "green", "gold", "gold_doaj", "hybrid", "bronze", "green_only"],
expected_coki["oa"],
actual_coki["oa"],
"color",
["oa", "green", "gold", "gold_doaj", "hybrid", "bronze", "green_only", "black"],
)

# COKI Access types
self.assert_sub_fields(
expected_item,
actual_item,
"oa_coki",
expected_coki["oa"],
actual_coki["oa"],
"coki",
[
"open",
"closed",
Expand All @@ -635,6 +636,9 @@ def assert_aggregate(self, expected: List[Dict], actual: List[Dict]):
],
)

# Repositories
self.assertEqual(expected_coki["repositories"], actual_coki["repositories"])

def assert_sub_fields(self, expected: Dict, actual: Dict, field: str, sub_fields: List[str]):
"""Checks that the sub fields in the aggregate match.
Expand Down

0 comments on commit 6a4de72

Please sign in to comment.