Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import zipfile
- import json
- import csv
- import pandas as pd
- def main():
- read_zip_file()
- # viide https://codeyarns.com/2013/10/03/how-to-read-contents-of-zip-file-in-python/
- def read_zip_file():
- csv_file = list()
- columns1 = ["keskmine_kiirus", "kiiruse_standardhälve", "hiire_koguteekond",
- "hiire_alguse_ja_lõpppunkti_vaheline_suhe", "sugu", "vanus", "faili_nimi"]
- FILE_PATH = ""
- zfile = zipfile.ZipFile(FILE_PATH)
- mouse_logger_att = 'mlogdict'
- for zipInfo in zfile.infolist():
- json_string = get_json(zfile, zipInfo)
- mlogdict = json_string[mouse_logger_att]
- new_dict = {k: speed(v)for (k, v) in mlogdict.items()}
- new_dict['sugu'] = json_string['sugu']
- new_dict['vanus'] = json_string['vanus']
- new_dict['faili_nimi'] = zipInfo.filename
- csv_file.append(new_dict)
- df = pd.DataFrame(csv_file, columns=columns1, dtype=int)
- print(df)
- df.to_csv("/Users/henrivajak/Desktop/file1.csv", index=False, columns=columns1)
- def speed(v):
- mouse_journey = get_mouse_journey(v)
- elapsed_time = v[-1][-1] - v[0][-1]
- return mouse_journey/elapsed_time
- def get_mouse_journey(exerice_matrix):
- # first element is x and then y and the timestamp
- mouse_journey = 0
- last_element = []
- for index, value in enumerate(exerice_matrix):
- if index == 0:
- last_element = value
- continue
- if index != len(exerice_matrix):
- mouse_journey += pythagrous(value[0], value[1], last_element[0], last_element[1])
- last_element = value
- return mouse_journey
- def pythagrous(source_x, source_y, target_x, target_y):
- return (((target_x - source_x) ** 2) + ((target_y - source_y) ** 2)) ** (1/2)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement