Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.96 KB | None | 0 0
  1. def month_to_number(month_string): # Returns the zero padded number of a Dutch month
  2.     handlers = {"januari": 1,
  3.                 "februari": 2,
  4.                 "maart": 3,
  5.                 "april": 4,
  6.                 "mei": 5,
  7.                 "juni": 6,
  8.                 "juli": 7,
  9.                 "augustus": 8,
  10.                 "september": 9,
  11.                 "oktober": 10,
  12.                 "november": 11,
  13.                 "december": 12}
  14.     return '{:02d}'.format(handlers[month_string]) # Return a string of a zero padded int
  15.  
  16. def string_to_datetime(string_date): # Returns a datetime object from a custom time format, e.g "vrijdag 19 juni 2015" -> datetime object
  17.     string_date_without_day = " ".join(string_date.split()[1:]) # Splits string_date and joins it from [1:]
  18.     string_date_numbers = "{day}-{month}-{year}".format(day = string_date_without_day.split()[0], month = month_to_number(string_date_without_day.split()[1]), year = string_date_without_day.split()[2])
  19.  
  20.     return datetime.strptime(string_date_numbers, "%d-%m-%Y")
  21.  
  22. cur.execute("SELECT * FROM history")
  23.  
  24. for info_tuple in cur.fetchall():
  25.     dates.append(string_to_datetime(info_tuple[0]))
  26.     if ", " in str(info_tuple[2]): # I couldn't put a list in an SQLite3 database, so I used ", ".join([1, 2, 3]). This code appends the length of the list to the list free
  27.         free.append(len(info_tuple[2].split(", ")))
  28.     else:
  29.         free.append(len(str(info_tuple[2])))
  30.     if ", " in str(info_tuple[3]): # Same as above, but for change
  31.         change.append(len(info_tuple[3].split(", ")))
  32.     else:
  33.         change.append(len(str(info_tuple[3])))
  34.     if ", " in str(info_tuple[4]): # Same as above, but for star
  35.         star.append(len(info_tuple[4].split(", ")))
  36.     else:
  37.         star.append(len(str(info_tuple[4])))
  38.  
  39. df = pd.DataFrame({"Datum": dates, "Vrij": free, "Roosterwijziging": change, "Steruur": star})
  40.  
  41. df.plot(x = "Datum", y = ["Vrij", "Roosterwijziging", "Steruur"])
  42. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement