conference_footprint

compute the CO2 footprint of an academic conference
git clone https://a3nm.net/git/conference_footprint/
Log | Files | Refs | LICENSE

compute.py (1436B)


      1 #!/usr/bin/env python3
      2 
      3 import sys
      4 import csv
      5 
      6 airports = {}
      7 
      8 datafile = sys.argv[1]
      9 localcode = sys.argv[2]
     10 
     11 with open('airports.dat', 'r') as f:
     12     csvreader = csv.reader(f)
     13     for row in csvreader:
     14         code = row[4]
     15         lat = row[6]
     16         lon = row[7]
     17         if '\\' in code:
     18             continue
     19         assert(code not in airports.keys())
     20         airports[code] = (lat, lon)
     21 
     22 n_participants = 0
     23 n_nonlocals = 0
     24 n_nonlocal_trips = 0
     25 n_extend = 0
     26 
     27 with open(datafile, 'r') as f:
     28     csvreader = csv.reader(f)
     29     for row in csvreader:
     30         fromcode = row[0]
     31         frommode = row[1]
     32         tocode = row[2]
     33         tomode = row[3]
     34         n_participants += 1
     35         if fromcode == localcode:
     36             assert (frommode in ["local", "other", ""])
     37             assert (tomode in ["local", "other", ""])
     38             assert (tocode == localcode)
     39             continue
     40         if frommode == "":
     41             frommode = "other"
     42         if tomode == "":
     43             tomode = "other"
     44         assert (frommode in ["bus/coach", "plane", "train", "other"])
     45         assert (tomode in ["bus/coach", "plane", "train", "other"])
     46         n_nonlocals += 1
     47         for (mode, code) in [(frommode, fromcode), (tomode, tocode)]:
     48             print (','.join((mode, airports[code][0], airports[code][1])))
     49 
     50 print("%d total participants" % n_participants, file=sys.stderr)
     51 print("%d nonlocal participants" % n_nonlocals, file=sys.stderr)