Skip to content

Commit

Permalink
add slope data to navigo 3-C data #43
Browse files Browse the repository at this point in the history
  • Loading branch information
robindemourat committed Dec 22, 2024
1 parent 32fcafc commit bfcd0a1
Show file tree
Hide file tree
Showing 3 changed files with 311 additions and 303 deletions.
3 changes: 2 additions & 1 deletion datascripts/3A-for-viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@
with open('module_intro_C/war_navigo.csv', 'r') as f1:
r = DictReader(f1)
for year in r:
slope = float(year["slope"])
data.append({
"year": year["year"],
"data_type": "navigation",
"value": float(year['entrées']) if year['entrées']!='' else None,
"kind" : year["source"],
# "slope" : ,
"slope" : f"{'+' if slope>0 else ''}{slope*100:0.1f}%/an",
# "reg_point": ,
"peace_reg_memory": year["reg_mem"],
"peace_reg": year["reg_no_mem"],
Expand Down
17 changes: 12 additions & 5 deletions datascripts/module_intro_C/compute_navigo.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,18 @@ def war_reg(data, memory):
# navigo
war_years = [str(y) for ys in wars for y in ys]
reg_navigo = defaultdict(lambda:defaultdict(str))
slope_navigo = defaultdict(lambda:defaultdict(str))

(score, slope, y0) = regress.regress("carriere", {"carriere": carriere},"")
slope_carriere = slope
average_loss_navigo={}
for variable, data in navigo.items():
data_peace_navigo = {year:int(value) for year,value in navigo[variable].items() if year not in war_years}
print(variable, data_peace_navigo)
(score, slope, y0) = regress.regress("navigo tonnage", {"navigo tonnage": data_peace_navigo},"")
for year in years:
reg_navigo[variable][year] = math.exp(slope*int(year)+y0)
slope_navigo[variable][year] = slope

navigo_loss_rates = [(navigo[variable][year] - reg_navigo[variable][year])/reg_navigo[variable][year] for year in war_years if navigo[variable][year] != '']
average_loss_navigo[variable] = 0
Expand All @@ -72,19 +77,19 @@ def war_reg(data, memory):
average_loss_carriere_no_mem = sum(carriere_loss_rates_no_mem)/len(carriere_loss_rates_no_mem)
print("average loss carriere no mem", average_loss_carriere_no_mem )


with open("war_navigo.csv", "w") as of:
writer = csv.DictWriter(of, ["year", "source","entrées", "reg_mem", "reg_no_mem", "avg_loss_label", "avg_loss", "avg_loss_no_mem", "avg_loss_no_mem_label"])
writer = csv.DictWriter(of, ["year", "source","entrées", "reg_mem", "reg_no_mem", "avg_loss_label", "avg_loss", "avg_loss_no_mem", "avg_loss_no_mem_label", "slope"])

writer.writeheader()
for year in years:

# print('carrière slope', slope_carriere);
writer.writerow({
"year": year,
"source": "Carriere",
"entrées" : carriere[year],
"reg_mem": reg_memory[year],
"reg_no_mem": reg_no_memory[year],
"slope": slope_carriere,
"avg_loss_label": f"Perte memoire{average_loss_carriere_mem*100:0.1f}%",
"avg_loss_no_mem_label": f"Perte {average_loss_carriere_no_mem*100:0.1f}%",
"avg_loss":average_loss_carriere_mem,
Expand All @@ -100,5 +105,7 @@ def war_reg(data, memory):
"reg_no_mem": "",
"avg_loss_label": f"Perte memoire{average_loss_navigo[variable]*100:0.1f}%",
"avg_loss":average_loss_navigo[variable],
"avg_loss_no_mem": ""
})
"avg_loss_no_mem": "",
"slope": slope_navigo[variable][year]
})

Loading

0 comments on commit bfcd0a1

Please sign in to comment.