Skip to content

Commit 340c78d

Browse files
authored
Merge pull request #305 from creativecommons/improve-gcs-process-and-report
Improve GCS process and report scripts
2 parents 98ffd2e + a715ad7 commit 340c78d

2 files changed

Lines changed: 39 additions & 24 deletions

File tree

‎scripts/2-process/gcs_process.py‎

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,27 +94,29 @@ def process_product_totals(args, count_data):
9494
"Licenses version 1.0": 0,
9595
"CC0 1.0": 0,
9696
"Public Domain Mark 1.0": 0,
97-
"Certification 1.0 US": 0,
97+
"CERTIFICATION 1.0 US": 0,
9898
}
9999
for row in count_data.itertuples(index=False):
100100
tool = row[0]
101101
count = row[1]
102-
if tool.startswith("PDM"):
102+
if tool == "PDM 1.0":
103103
key = "Public Domain Mark 1.0"
104-
elif "CC0" in tool:
105-
key = "CC0 1.0"
106-
elif "PUBLICDOMAIN" in tool:
107-
key = "Certification 1.0 US"
108-
elif "4.0" in tool:
104+
elif tool == "CC0 1.0":
105+
key = tool
106+
elif tool == "CERTIFICATION 1.0 US":
107+
key = tool
108+
elif tool.startswith("CC ") and tool.endswith("4.0"):
109109
key = "Licenses version 4.0"
110-
elif "3.0" in tool:
110+
elif tool.startswith("CC ") and "3.0" in tool:
111111
key = "Licenses version 3.0"
112-
elif "2." in tool:
112+
elif tool.startswith("CC ") and "2." in tool:
113113
key = "Licenses version 2.x"
114-
elif "1.0" in tool:
114+
elif tool.startswith("CC ") and "1.0" in tool:
115115
key = "Licenses version 1.0"
116116
else:
117-
raise shared.QuantifyingException("Invalid TOOL_IDENTIFIER")
117+
raise shared.QuantifyingException(
118+
f"Invalid TOOL_IDENTIFIER: {tool}"
119+
)
118120
data[key] += count
119121

120122
data = pd.DataFrame(
@@ -129,7 +131,11 @@ def process_latest_prior_retired_totals(args, count_data):
129131
Process count data: totals by unit in three categories: latest, prior,
130132
and retired
131133
"""
132-
LOGGER.info(process_latest_prior_retired_totals.__doc__.strip())
134+
LOGGER.info(
135+
process_latest_prior_retired_totals.__doc__.strip().replace(
136+
"\n ", ""
137+
)
138+
)
133139
# https://creativecommons.org/retiredlicenses/
134140
retired = [
135141
# DevNations,
@@ -144,14 +150,14 @@ def process_latest_prior_retired_totals(args, count_data):
144150
"CC NC-SAMPLING+",
145151
# NonCommercial-ShareAlike
146152
"CC NC-SA ",
147-
# Public Domain Dedication and Certification
148-
"CC PUBLICDOMAIN",
149153
# Sampling
150154
"CC SAMPLING ",
151155
# Sampling+
152156
"CC SAMPLING+ ",
153157
# ShareAlike
154158
"CC SA ",
159+
# Certification
160+
"CERTIFICATION ",
155161
]
156162
data = {"latest": {}, "prior": {}, "retired": {}}
157163
status = {"Latest": 0, "Prior": 0, "Retired": 0}
@@ -218,7 +224,7 @@ def process_totals_by_free_cultural(args, count_data):
218224
for row in count_data.itertuples(index=False):
219225
tool = row[0]
220226
count = row[1]
221-
if tool.startswith("PDM") or "CC0" in tool or "PUBLICDOMAIN" in tool:
227+
if tool in ("CERTIFICATION 1.0 US", "CC0 1.0", "PDM 1.0"):
222228
key = "Approved for Free Cultural Works"
223229
else:
224230
parts = tool.split()
@@ -252,7 +258,7 @@ def process_totals_by_restrictions(args, count_data):
252258
for row in count_data.itertuples(index=False):
253259
tool = row[0]
254260
count = row[1]
255-
if tool.startswith("PDM") or "CC0" in tool or "PUBLICDOMAIN" in tool:
261+
if tool.startswith("PDM") or "CC0" in tool or "CERTIFICATION" in tool:
256262
key = "level 0 - unrestricted"
257263
else:
258264
parts = tool.split()

‎scripts/3-report/gcs_report.py‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def plot_products(args):
122122
LOGGER.info(f"data file: {file_path.replace(PATHS['repo'], '.')}")
123123
name_label = "CC legal tool product"
124124
data = shared.open_data_file(LOGGER, file_path, index_col=name_label)
125-
125+
data.index = data.index.map(lambda x: x.replace("CC0 1.0", "CC0 1.0"))
126126
data = data[::-1] # reverse order
127127

128128
title = "Products totals and percentages"
@@ -213,6 +213,7 @@ def plot_latest_tools(args):
213213
LOGGER.info(f"data file: {file_path.replace(PATHS['repo'], '.')}")
214214
name_label = "CC legal tool"
215215
data = shared.open_data_file(LOGGER, file_path, index_col=name_label)
216+
data.index = data.index.map(lambda x: x.replace(" ", " "))
216217
data.sort_values(name_label, ascending=False, inplace=True)
217218

218219
title = "Latest CC legal tools"
@@ -242,6 +243,9 @@ def plot_latest_tools(args):
242243
image_path,
243244
"The plot shows the latest Creative Commons (CC) legal tool totals and"
244245
" percentages.",
246+
"The latest tools include Licenses version 4.0 (CC BY 4.0, CC BY-NC"
247+
" 4.0, CC BY-NC-ND 4.0, CC BY-NC-SA 4.0, CC-BY-ND 4.0, CC BY-SA 4.0),"
248+
" CC0 1.0, and the Public Domain Mark (PDM 1.0).",
245249
)
246250

247251

@@ -256,6 +260,7 @@ def plot_prior_tools(args):
256260
LOGGER.info(f"data file: {file_path.replace(PATHS['repo'], '.')}")
257261
name_label = "CC legal tool"
258262
data = shared.open_data_file(LOGGER, file_path, index_col=name_label)
263+
data.index = data.index.map(lambda x: x.replace(" ", " "))
259264
data.sort_values(name_label, ascending=False, inplace=True)
260265

261266
title = "Prior CC legal tools"
@@ -284,7 +289,8 @@ def plot_prior_tools(args):
284289
title,
285290
image_path,
286291
"The plot shows prior Creative Commons (CC) legal tool totals and"
287-
" percentages. The unit names have been normalized (~~`CC BY-ND-NC`~~"
292+
" percentages. Prior CC licenses include versions 1.0, 2.0, 2.1, 2.5,"
293+
" and 3.0. The unit names have been normalized (~~`CC BY-ND-NC`~~"
288294
" => `CC BY-NC-ND`).",
289295
)
290296

@@ -301,6 +307,7 @@ def plot_retired_tools(args):
301307
LOGGER.info(f"data file: {file_path.replace(PATHS['repo'], '.')}")
302308
name_label = "CC legal tool"
303309
data = shared.open_data_file(LOGGER, file_path, index_col=name_label)
310+
data.index = data.index.map(lambda x: x.replace(" ", " "))
304311
data.sort_values(name_label, ascending=False, inplace=True)
305312

306313
title = "Retired CC legal tools"
@@ -379,14 +386,15 @@ def plot_countries_highest_usage(args):
379386
SECTION_TITLE,
380387
title,
381388
image_path,
382-
"The plot shows countries with the highest useage of the latest"
389+
"The plot shows countries with the highest usage of the latest"
383390
" Creative Commons (CC) legal tools.",
384391
"The latest tools include Licenses version 4.0 (CC BY 4.0, CC BY-NC"
385392
" 4.0, CC BY-NC-ND 4.0, CC BY-NC-SA 4.0, CC-BY-ND 4.0, CC BY-SA 4.0),"
386393
" CC0 1.0, and the Public Domain Mark (PDM 1.0).\n"
387394
"\n"
388-
f"The complete data set indicates there are a total of {total_count}"
389-
" online works using one of the latest CC legal tools.",
395+
"The complete countries data set indicates there are a total of"
396+
f" {total_count} online works using one of the latest CC legal tools."
397+
" This conflicts with the languages data set, below.",
390398
)
391399

392400

@@ -433,14 +441,15 @@ def plot_languages_highest_usage(args):
433441
SECTION_TITLE,
434442
title,
435443
image_path,
436-
"The plot shows the languages with the highest useage of the latest"
444+
"The plot shows the languages with the highest usage of the latest"
437445
" Creative Commons (CC) legal tools.",
438446
"The latest tools include Licenses version 4.0 (CC BY 4.0, CC BY-NC"
439447
" 4.0, CC BY-NC-ND 4.0, CC BY-NC-SA 4.0, CC-BY-ND 4.0, CC BY-SA 4.0),"
440448
" CC0 1.0, and the Public Domain Mark (PDM 1.0).\n"
441449
"\n"
442-
f"The complete data set indicates there are a total of {total_count}"
443-
" online works using one of the latest CC legal tools.",
450+
"The complete languages data set indicates there are a total of"
451+
f" {total_count} online works using one of the latest CC legal tools."
452+
" This conflicts with the countries data set, above.",
444453
)
445454

446455

0 commit comments

Comments
 (0)