Guest User

Untitled

a guest
Feb 25th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. # Created with Python 2.7
  2.  
  3. # Reads in from source and creates a file at destination
  4. source_file = "measurements.csv"
  5. destination_file = "converted_measurements.csv"
  6. height = 1.83 # in meters
  7.  
  8. def write_file(lines):
  9. with open(destination_file, "w") as output:
  10. for line in lines:
  11. output.write(line + "\n")
  12.  
  13.  
  14. def bmi_calc(weight):
  15. bmi = round(weight / (height * height), 2)
  16. return bmi
  17.  
  18.  
  19. def date_flip(run_date):
  20. # From 2017-04-08 00:00:00 to 08-04-2017
  21. a = run_date.split(" ")
  22. b = a[0].split("-")
  23. return "{0}-{1}-{2}".format(b[2], b[1], b[0])
  24.  
  25.  
  26. def filter_lines(runkeeper_data):
  27. array = []
  28. for line in runkeeper_data:
  29. points = line.split(",")
  30. # has other things as well
  31. if points[1] == 'weight':
  32. array.append(convert_line(points))
  33. return array
  34.  
  35.  
  36. def convert_line(runkeeper_points):
  37. measurement_date = date_flip(runkeeper_points[0])
  38. weight = float(runkeeper_points[2])
  39. bmi = bmi_calc(weight)
  40. fitbit_line = "\"{0}\",\"{1}\",\"{2}\",\"{3}\"".format(measurement_date, int(round(weight)), bmi, 0)
  41. return fitbit_line
  42.  
  43. runkeeper_data = []
  44.  
  45. with open(source_file) as f:
  46. for line in f:
  47. runkeeper_data.append(line)
  48.  
  49. header = """Body
  50. Date,Weight,BMI,Fat"""
  51.  
  52. lines = [header] + filter_lines(runkeeper_data)
  53.  
  54. write_file(lines)
Add Comment
Please, Sign In to add comment