예제 #1
0
    # First [ to make COUNTY_NAME.json valid json
    output.write("[")

    # Hacky way of making sure there's not an extra comma
    i = 0
    for line in data:
        match = reg.search(line)
        if match:  # If line matches regex, write to new file in new format
            if i == 0:
                output.write(
                    reg.sub(
                        "[\"" + match.group(1) + "\"," + match.group(2) + "]",
                        line))
                i = 1
            else:
                output.write(
                    reg.sub(
                        ",[\"" + match.group(1) + "\"," + match.group(2) + "]",
                        line))

    # Last ] to make COUNTY_NAME.json valid json
    output.write("]")

    data.close()
    output.close()


if __name__ == "__main__":
    counties = loadWithJSON('counties.json')
    for i in counties:
        ParseNytData(i[1], i[2])
예제 #2
0
from file_utils import loadWithJSON


## Will load all Harrisonburg and Rockingham data into a list of lists
## Each element in the main list will contain a list of two items, the str:date and int:cases
harrisonburg_data = loadWithJSON('harrisonburg.json')
rockingham_data = loadWithJSON('rockingham.json')

## Print all elements in the list as an example
for data in harrisonburg_data:
    date = data[0]
    cases = data[1]
    print('On '+date + ' there were '+ str(cases) +' cases in Harrisonburg')

print('When was the first positive COVID case in Rockingham County and Harrisonburg?')

print('What day was the maximum number of cases recorded in Harrisonburg and Rockingham County?')

print('What was the worst week in the city/county for new COVID cases? '
      'When was the rise in cases the fastest over a seven day period?')
예제 #3
0
from file_utils import loadWithJSON
from covid_dataset import CovidDataset
from parse_nyt_data import ParseNytData
import constants

# Dictionary of names of counties and corresponding filenames with county data.
# Edit update_county_data to analyze data from additional counties
files = loadWithJSON('counties.json')

# Make dictionary with key="COUNTY_NAME" and value=COVID_DATASET_OBJECT
data = {}
for i in files:
    try:
        ParseNytData(i[1], i[2])
        data[i[0]] = CovidDataset(loadWithJSON(i[2]))
    except:
        print("\nFile %s does not exist" % (i[2]))

print('\nWhen was the first positive COVID cases in each county?\n')

for key in data:
    print("%s: %s" % (key, data[key].get_first_positive()))

print('\nWhat day was the maximum number of cases recorded in each county?\n')

for key in data:
    print("%s: %s" % (key, data[key].get_max_case_day()))

print('\nWhat was the worst week in each city/county for new COVID cases? '
      'When was the rise in cases the fastest over a seven day period?'
      '\n')
예제 #4
0
            if increase > max_case_num:
                max_case_day = self.data[data_index][0]
                max_case_num = increase
        return max_case_day

    def get_worst_n_days(self, days: int) -> str:
        """
        Returns the worst rolling n-day period in terms of the
        total number of cases over that period.
        """
        days -= 1
        # Sets worst day number and range to first n days
        worst_seven_days_num = self.data[days][1] - self.data[0][1]
        worst_seven_days_range = [0, days]

        for i in range(0, len(self.data) - days):
            n_day_diff = [datapoint[1] for datapoint in self.data[i:i + days]]
            if n_day_diff[-1] - n_day_diff[0] > worst_seven_days_num:
                worst_seven_days_num = n_day_diff[-1] - n_day_diff[0]
                worst_seven_days_range = [i, i + days]

        return (str(self.data[worst_seven_days_range[0]][0]),
                str(self.data[worst_seven_days_range[1]][0]))


if __name__ == "__main__":
    harrisonburg_data = loadWithJSON('harrisonburg.json')
    print(
        CovidDataset(harrisonburg_data).get_worst_n_days(
            constants.DAYS_IN_WEEK))