-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
made some changes to CalculationHandler and TwoIMUs
- Loading branch information
Showing
8 changed files
with
161 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import csv | ||
import sys | ||
# insert at 1, 0 is the script path (or '' in REPL) | ||
sys.path.insert(1, '../api') | ||
import CalculationHandler | ||
import TwoIMUs | ||
import IMUDataProcessing | ||
import MoodClassifier | ||
|
||
|
||
JSON_PATH = "../SavedJSONs/" | ||
CSV_PATH = "./" | ||
tail_file_name = "butterbean_4_16_alert-tail.json" | ||
body_file_name = "butterbean_4_16_alert-body.json" | ||
write_file_name = "butterbean_4_16_alert.csv" | ||
|
||
tailFilteredData = IMUDataProcessing.filterFile(JSON_PATH + tail_file_name) | ||
bodyFilteredData = IMUDataProcessing.filterFile(JSON_PATH + body_file_name) | ||
|
||
quatsList, timesList = TwoIMUs.get_quats_from_filtered_data(tailFilteredData, bodyFilteredData) | ||
xVecsList = TwoIMUs.quats_to_vectors(quatsList) | ||
|
||
|
||
calculation_module = CalculationHandler.Calculation_Module() | ||
|
||
|
||
# open the file in the write mode | ||
with open(CSV_PATH + write_file_name, 'w') as f: | ||
# create the csv writer | ||
writer = csv.writer(f) | ||
labelrow = ["Frequency","Amplitude","Pitches","Angles","Side Bias","Mood","Image Url","Timestamps"] | ||
# write a row to the csv file | ||
writer.writerow(labelrow) | ||
|
||
for i in range(len(xVecsList)): | ||
# window i | ||
# row i+1 | ||
pitches, angles = calculation_module.get_pitches_angles_from_vectors(xVecsList[i]) | ||
frequency = calculation_module.calculate_frequency(angles, timesList[i]) | ||
amplitude = calculation_module.calculate_average_amplitude(angles) | ||
side_bias = calculation_module.calculate_side_bias_from_vectors(xVecsList[i]) | ||
mood = MoodClassifier.get_mood(frequency, amplitude, pitches, angles, side_bias) | ||
image_url = "" | ||
row = [frequency, amplitude, pitches, angles, side_bias, mood, image_url, timesList[i]] | ||
# write a row to the csv file | ||
writer.writerow(row) | ||
|
||
|
||
|
||
# with open('temp.csv') as csv_file: | ||
# csv_reader = csv.reader(csv_file, delimiter=',') | ||
# line_count = 0 | ||
# for row in csv_reader: | ||
# row_count = 0 | ||
# for cell in row: | ||
# print(cell) | ||
# print(type(cell)) | ||
# if(row_count == 2): | ||
# cell = cell[1:-1].split(", ") | ||
# print(cell) | ||
# print(type(cell)) | ||
# row_count+=1 | ||
# line_count+=1 | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.