Populate a programming_language tallies list of mappings such as {value: "programming_language", count: "count of occurences"} sorted by decreasing count.
(resource, children, keep_details=False)
| 218 | |
| 219 | |
| 220 | def language_tallies(resource, children, keep_details=False): |
| 221 | """ |
| 222 | Populate a programming_language tallies list of mappings such as |
| 223 | {value: "programming_language", count: "count of occurences"} |
| 224 | sorted by decreasing count. |
| 225 | """ |
| 226 | PROG_LANG = 'programming_language' |
| 227 | languages = [] |
| 228 | prog_lang = getattr(resource, PROG_LANG , []) |
| 229 | if not prog_lang: |
| 230 | if resource.is_file: |
| 231 | # also count files with no detection |
| 232 | languages.append(None) |
| 233 | else: |
| 234 | languages.append(prog_lang) |
| 235 | |
| 236 | # Collect direct children expression summaries |
| 237 | for child in children: |
| 238 | child_tallies = get_resource_tallies(child, key=PROG_LANG, as_attribute=keep_details) or [] |
| 239 | for child_tally in child_tallies: |
| 240 | child_sum_val = child_tally.get('value') |
| 241 | if child_sum_val: |
| 242 | values = [child_sum_val] * child_tally['count'] |
| 243 | languages.extend(values) |
| 244 | |
| 245 | # summarize proper |
| 246 | languages_counter = tally_languages(languages) |
| 247 | tallied = sorted_counter(languages_counter) |
| 248 | set_resource_tallies(resource, key=PROG_LANG, value=tallied, as_attribute=keep_details) |
| 249 | return tallied |
| 250 | |
| 251 | |
| 252 | def tally_languages(languages): |
nothing calls this directly
no test coverage detected