<commit_before>---
title: Organizing inside Your Source - Best Practices, Separation of Concerns
---

LONG EXERCISE STUB
## Rough Outline for Long Exercise

- Ex1: working program, ~50 lines long
    - take time to run & understand program
    - meet in small group to discuss alternate structure re: functions
    - individually refactor code into functions
    - swap code, implement new functionality
    - discuss choices, what did/didn't work

- Ex2: working program, ~200 lines long, procedural code with some functions
    - take time to understand program
    - meet to discuss OO options, considering current and future use
    - refactor into one or more classes
    - swap code, add functionality
    - discuss<commit_msg>Updating organizing_inner.md<commit_after>---
title: Organizing inside Your Source - Best Practices, Separation of Concerns
---

## Instructions from aggregate_rural_and_urban.py:

This script takes an input file ("all_cases.csv") that contains location-stratified
disease time series data, and aggregates the disease incidence based on whether the
location was rural or urban.

You will be making multiple changes to the code below.  Each time you make a 
substantial change, verify that you have not changed the output from the program.

The Exercise:

1) Read through, understand, and annotate the code.  If you do not understand a line,
investigate it by experimenting, checking python references, and talking to others.

2) If there anything simple that can be done to make the code more readable or
manageable, go ahead and do that--things like renaming variables or reducing the use
of "magical" numbers.

3) Break the code up into functional units, and then turn those units into functions.

4) Write a class that can represent the input data in a useful way.  Create a parser
function in the class that takes a line of text from the file and returns structured
data that is useful and easy to understand.
{'fraction_non_alphanumeric': 0.046762589928057555, 'fraction_numerical': 0.005652620760534429, 'mean_word_length': 3.929113924050633, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5089745', 'n_tokens_mistral': 497, 'n_tokens_neox': 471, 'n_words': 279}