Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

quantified-self-lib

Package Overview
Dependencies
Maintainers
1
Versions
134
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

quantified-self-lib - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

6

lib/duration/duration.class.abstract.d.ts
import { DurationClassInterface } from './duration.class.interface';
import { StatsClassAbstract } from '../stats/stats.class.abstract';
import { DataPause } from '../data/data.pause';
import { DataDuration } from '../data/data.duration';
export declare abstract class DurationClassAbstract extends StatsClassAbstract implements DurationClassInterface {

@@ -7,2 +9,6 @@ readonly startDate: Date;

protected constructor(statDate: Date, endDate: Date);
getDuration(): DataDuration;
getPause(): DataPause;
setDuration(duration: DataDuration): void;
setPause(pause: DataPause): void;
}

@@ -14,2 +14,4 @@ "use strict";

var stats_class_abstract_1 = require("../stats/stats.class.abstract");
var data_pause_1 = require("../data/data.pause");
var data_duration_1 = require("../data/data.duration");
var DurationClassAbstract = /** @class */ (function (_super) {

@@ -27,4 +29,16 @@ __extends(DurationClassAbstract, _super);

}
DurationClassAbstract.prototype.getDuration = function () {
return this.stats.get(data_duration_1.DataDuration.className);
};
DurationClassAbstract.prototype.getPause = function () {
return this.stats.get(data_pause_1.DataPause.className);
};
DurationClassAbstract.prototype.setDuration = function (duration) {
this.stats.set(data_duration_1.DataDuration.className, duration);
};
DurationClassAbstract.prototype.setPause = function (pause) {
this.stats.set(data_pause_1.DataPause.className, pause);
};
return DurationClassAbstract;
}(stats_class_abstract_1.StatsClassAbstract));
exports.DurationClassAbstract = DurationClassAbstract;

@@ -0,4 +1,10 @@

import { DataPause } from '../data/data.pause';
import { DataDuration } from '../data/data.duration';
export interface DurationClassInterface {
readonly startDate: Date;
readonly endDate: Date;
getDuration(): DataDuration;
getPause(): DataPause;
setDuration(duration: DataDuration): void;
setPause(pause: DataPause): void;
}

10

lib/events/adapters/importers/fit/importer.fit.js

@@ -61,6 +61,4 @@ "use strict";

debugger;
// Create an event
var event = new event_1.Event(name);
// Iterate over the sessions and create their activities
fitDataObject.activity.sessions.forEach(function (sessionObject) {
var activities = fitDataObject.activity.sessions.map(function (sessionObject) {
// Get the activity from the sessionObject

@@ -81,4 +79,8 @@ var activity = _this.getActivityFromSessionObject(sessionObject, fitDataObject);

activity.sortPointsByDate();
event.addActivity(activity);
return activity;
});
// Create an event
// @todo check if the start and end date can derive from the file
var event = new event_1.Event(name, activities[0].startDate, activities[activities.length - 1].endDate);
activities.forEach(function (activity) { return event.addActivity(activity); });
// Set the totals for the event

@@ -85,0 +87,0 @@ event.setDuration(new data_duration_1.DataDuration(event.getActivities().reduce(function (duration, activity) { return activity.getDuration().getValue(); }, 0)));

4

lib/events/adapters/importers/gpx/importer.gpx.js

@@ -34,4 +34,2 @@ "use strict";

var parsedGPX = GXParser(gpx);
// Create an event
var event = new event_1.Event(name);
// Create a creator

@@ -58,2 +56,4 @@ var creator = new creator_1.Creator(parsedGPX.creator);

laps.forEach(function (lap) { return activity.addLap(lap); });
// Create an event
var event = new event_1.Event(name, activity.startDate, activity.endDate);
// Add the activity to the event

@@ -60,0 +60,0 @@ event.addActivity(activity);

@@ -21,8 +21,3 @@ "use strict";

var eventJSONObject = JSON.parse(jsonString);
var event = new event_1.Event(eventJSONObject.name);
event.setID(eventJSONObject.id);
eventJSONObject.stats.forEach(function (stat) {
event.addStat(data_store_1.DynamicDataLoader.getDataInstance(stat.className, stat.value));
});
var _loop_1 = function (activityObject) {
var activities = eventJSONObject.activities.map(function (activityObject) {
var creator = new creator_1.Creator(activityObject.creator.name);

@@ -44,3 +39,3 @@ creator.hwInfo = activityObject.creator.hwInfo;

});
var _loop_2 = function (lapObject) {
var _loop_1 = function (lapObject) {
var lap = new lap_1.Lap(new Date(lapObject.startDate), new Date(lapObject.endDate), lapObject.type);

@@ -55,5 +50,4 @@ lap.setID(lapObject.id);

var lapObject = _a[_i];
_loop_2(lapObject);
_loop_1(lapObject);
}
event.addActivity(activity);
if (activityObject.intensityZones) {

@@ -83,7 +77,10 @@ for (var key in activityObject.intensityZones) {

}
};
for (var _i = 0, _a = eventJSONObject.activities; _i < _a.length; _i++) {
var activityObject = _a[_i];
_loop_1(activityObject);
}
return activity;
});
var event = new event_1.Event(eventJSONObject.name, new Date(eventJSONObject.startDate), new Date(eventJSONObject.endDate));
event.setID(eventJSONObject.id);
activities.forEach(function (activity) { return event.addActivity(activity); });
eventJSONObject.stats.forEach(function (stat) {
event.addStat(data_store_1.DynamicDataLoader.getDataInstance(stat.className, stat.value));
});
resolve(event);

@@ -90,0 +87,0 @@ });

@@ -78,8 +78,2 @@ "use strict";

var eventJSONObject = JSON.parse(jsonString);
// Create an event
var event = new event_1.Event('');
// Populate the event stats from the Header Object
_this.getStats(eventJSONObject.DeviceLog.Header).forEach(function (stat) {
event.addStat(stat);
});
// Create a creator and pass it to all activities (later)

@@ -124,6 +118,11 @@ var creator = new creator_1.Creator(importer_suunto_device_names_1.ImporterSuuntoDeviceNames[eventJSONObject.DeviceLog.Device.Name] // Try to get a listed name

// Create the stats these are a 1:1 ref arrays
_this.getStats(activityWindows[index]).forEach(function (stat) {
activity.addStat(stat);
});
if (activityWindows[index]) {
_this.getStats(activityWindows[index]).forEach(function (stat) {
activity.addStat(stat);
});
}
// Add the pause from end date minurs start date and removing the duration as widows do not contain the pause time
if (!activity.getDuration()) {
activity.setDuration(new data_duration_1.DataDuration((activity.endDate.getTime() - activity.startDate.getTime()) / 1000));
}
activity.setPause(new data_pause_1.DataPause((activity.endDate.getTime() - activity.startDate.getTime()) / 1000 - activity.getDuration().getValue()));

@@ -161,8 +160,14 @@ // Set the zones for the activity @todo fix

// @todo here is the real info LapTypes[lapEventSample.Events[0].Lap.Type
var lap = new lap_1.Lap(lapStartDatesByType[lapEventSample.Events[0].Lap.Type], lapEndDate, lap_types_1.LapTypes[lapWindows[index].Type]);
debugger;
var lap = new lap_1.Lap(lapStartDatesByType[lapEventSample.Events[0].Lap.Type], lapEndDate, lap_types_1.LapTypes[lapEventSample.Events[0].Lap.Type]);
lapStartDatesByType[lapEventSample.Events[0].Lap.Type] = lapEndDate;
_this.getStats(lapWindows[index]).forEach(function (stat) {
lap.addStat(stat);
});
if (lapWindows[index]) {
_this.getStats(lapWindows[index]).forEach(function (stat) {
lap.addStat(stat);
});
}
// Add the pause from end date minurs start date and removing the duration as widows do not contain the pause time
if (!lap.getDuration()) {
lap.setDuration(new data_duration_1.DataDuration((lap.endDate.getTime() - lap.startDate.getTime()) / 1000));
}
lap.setPause(new data_pause_1.DataPause((lap.endDate.getTime() - lap.startDate.getTime()) / 1000 - lap.getDuration().getValue()));

@@ -217,5 +222,10 @@ lapArray.push(lap);

// Add the activities to the event
activities.forEach(function (activity) {
activity.sortPointsByDate();
event.addActivity(activity);
activities.forEach(function (activity) { return activity.sortPointsByDate(); });
// Create an event
// @todo check if start and end date can derive from the json
var event = new event_1.Event('', activities[0].startDate, activities[activities.length - 1].endDate);
activities.forEach(function (activity) { return event.addActivity(activity); });
// Populate the event stats from the Header Object
_this.getStats(eventJSONObject.DeviceLog.Header).forEach(function (stat) {
event.addStat(stat);
});

@@ -222,0 +232,0 @@ // Generate stats

@@ -37,12 +37,8 @@ "use strict";

return new Promise(function (resolve, reject) {
// Init the event
var event = new event_1.Event(name);
event.setDistance(new data_distance_1.DataDistance(0));
event.setDuration(new data_duration_1.DataDuration(0));
event.setPause(new data_pause_1.DataPause(0));
var _loop_1 = function (activityElement) {
// Activities
var activities = Array.from(xml.getElementsByTagName('TrainingCenterDatabase')[0].getElementsByTagName('Activity'))
.map(function (activityElement) {
// TCX begins with laps, get them
var laps = _this.getLaps(activityElement.getElementsByTagName('Lap'));
var activity = new activity_1.Activity(new Date(activityElement.getElementsByTagName('Lap')[0].getAttribute('StartTime')), laps[laps.length - 1].endDate, activity_types_1.ActivityTypes[activityElement.getAttribute('Sport')] || activity_types_1.ActivityTypes['unknown'], _this.getCreator(activityElement.getElementsByTagName('Creator')[0]));
event.addActivity(activity);
// Go over the laps and start filling up the stats and creating the points

@@ -66,6 +62,2 @@ // @todo

// Todo perhaps think about distance if 0 to add the lap as pause
// Same for event
event.getDistance().setValue(event.getDistance().getValue() + lap.getDistance().getValue());
event.setDuration(new data_duration_1.DataDuration(event.getDuration().getValue() + lap.getDuration().getValue()));
event.getPause().setValue(event.getPause().getValue() + lap.getPause().getValue());
});

@@ -78,8 +70,55 @@ Array.from(activityElement.getElementsByTagName('Lap')).map(function (lapElement) {

activity.sortPointsByDate();
};
// Activities
for (var _i = 0, _a = xml.getElementsByTagName('TrainingCenterDatabase')[0].getElementsByTagName('Activity'); _i < _a.length; _i++) {
var activityElement = _a[_i];
_loop_1(activityElement);
}
return activity;
});
// Init the event
var event = new event_1.Event(name, activities[0].startDate, activities[activities.length - 1].endDate);
activities.forEach(function (activity) { return event.addActivity(activity); });
event.setDuration(new data_duration_1.DataDuration(event.getActivities().reduce(function (duration, activity) { return activity.getDuration().getValue(); }, 0)));
event.setDistance(new data_distance_1.DataDistance(event.getActivities().reduce(function (duration, activity) { return activity.getDistance() ? activity.getDistance().getValue() : 0; }, 0)));
event.setPause(new data_pause_1.DataPause(event.getActivities().reduce(function (duration, activity) { return activity.getPause().getValue(); }, 0)));
// for (const activityElement of <any>xml.getElementsByTagName('TrainingCenterDatabase')[0].getElementsByTagName('Activity')) {
// // TCX begins with laps, get them
// const laps = this.getLaps(activityElement.getElementsByTagName('Lap'));
// const activity = new Activity(
// new Date(activityElement.getElementsByTagName('Lap')[0].getAttribute('StartTime')),
// laps[laps.length - 1].endDate,
// ActivityTypes[<keyof typeof ActivityTypes>activityElement.getAttribute('Sport')] || ActivityTypes['unknown'],
// this.getCreator(activityElement.getElementsByTagName('Creator')[0]),
// );
// event.addActivity(activity);
//
// // Go over the laps and start filling up the stats and creating the points
// // @todo
// activity.setDuration(new DataDuration(0));
// activity.setDistance(new DataDistance(0));
// activity.setPause(new DataPause(0));
// activity.addStat(new DataEnergy(0));
//
// // Get the laps and add the total distance to the activity
// laps.forEach((lap: LapInterface) => {
// if (lap.getDuration().getValue() === 0) {
// return;
// }
// activity.addLap(lap);
// // Increment wrapper stats
// activity.getDistance().setValue(activity.getDistance().getValue() + lap.getDistance().getValue());
// activity.getDuration().setValue(activity.getDuration().getValue() + lap.getDuration().getValue());
// activity.getPause().setValue(activity.getPause().getValue() + lap.getPause().getValue());
//
// activity.addStat(new DataEnergy((<DataEnergy>activity.getStat(DataEnergy.className)).getValue() + (<DataEnergy>lap.getStat(DataEnergy.className)).getValue()));
// // Todo perhaps think about distance if 0 to add the lap as pause
//
// // Same for event
// event.getDistance().setValue(event.getDistance().getValue() + lap.getDistance().getValue());
// event.setDuration(new DataDuration(event.getDuration().getValue() + lap.getDuration().getValue()));
// event.getPause().setValue(event.getPause().getValue() + lap.getPause().getValue());
// });
//
// Array.from(activityElement.getElementsByTagName('Lap')).map((lapElement: any) => {
// this.getPoints(<any>lapElement.getElementsByTagName('Trackpoint')).map((point) => {
// activity.addPoint(point);
// });
// });
// activity.sortPointsByDate();
// }
event_utilities_1.EventUtilities.generateStats(event);

@@ -86,0 +125,0 @@ resolve(event);

import { EventInterface } from './event.interface';
import { ActivityInterface } from '../activities/activity.interface';
import { PointInterface } from '../points/point.interface';
import { StatsClassAbstract } from '../stats/stats.class.abstract';
export declare class Event extends StatsClassAbstract implements EventInterface {
import { DurationClassAbstract } from '../duration/duration.class.abstract';
export declare class Event extends DurationClassAbstract implements EventInterface {
name: string;
private activities;
constructor(name: string);
constructor(name: string, startDate: Date, endDate: Date);
addActivity(activity: ActivityInterface): void;

@@ -10,0 +10,0 @@ removeActivity(activityToRemove: ActivityInterface): void;

@@ -5,3 +5,4 @@ import { PointInterface } from '../points/point.interface';

import { ActivityInterface } from '../activities/activity.interface';
export interface EventInterface extends StatsClassInterface, SerializableClassInterface {
import { DurationClassInterface } from '../duration/duration.class.interface';
export interface EventInterface extends StatsClassInterface, DurationClassInterface, SerializableClassInterface {
name: string;

@@ -8,0 +9,0 @@ addActivity(activity: ActivityInterface): void;

@@ -13,7 +13,7 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var stats_class_abstract_1 = require("../stats/stats.class.abstract");
var duration_class_abstract_1 = require("../duration/duration.class.abstract");
var Event = /** @class */ (function (_super) {
__extends(Event, _super);
function Event(name) {
var _this = _super.call(this) || this;
function Event(name, startDate, endDate) {
var _this = _super.call(this, startDate, endDate) || this;
_this.activities = [];

@@ -82,3 +82,3 @@ _this.name = name;

return Event;
}(stats_class_abstract_1.StatsClassAbstract));
}(duration_class_abstract_1.DurationClassAbstract));
exports.Event = Event;

@@ -121,6 +121,3 @@ "use strict";

});
var mergeEvent = new event_1.Event("Merged at " + (new Date()).toISOString());
mergeEvent.setDistance(new data_distance_1.DataDistance(0));
mergeEvent.setDuration(new data_duration_1.DataDuration(0));
mergeEvent.setPause(new data_pause_1.DataPause(0));
var activities = [];
for (var _i = 0, events_1 = events; _i < events_1.length; _i++) {

@@ -130,10 +127,13 @@ var event_2 = events_1[_i];

var activity = _b[_a];
mergeEvent.addActivity(activity);
mergeEvent.getDistance().setValue(mergeEvent.getDistance().getValue() + activity.getDistance().getValue());
mergeEvent.getDuration().setValue(mergeEvent.getDuration().getValue() + activity.getDuration().getValue());
mergeEvent.getPause().setValue(mergeEvent.getPause().getValue() + activity.getPause().getValue());
// @todo merge the rest of the stats
activities.push(activity);
}
}
return resolve(mergeEvent);
var event = new event_1.Event("Merged at " + (new Date()).toISOString(), activities[0].startDate, activities[activities.length - 1].endDate);
activities.forEach(function (activity) { return event.addActivity(activity); });
// Set the totals for the event
event.setDuration(new data_duration_1.DataDuration(event.getActivities().reduce(function (duration, activity) { return activity.getDuration().getValue(); }, 0)));
event.setDistance(new data_distance_1.DataDistance(event.getActivities().reduce(function (duration, activity) { return activity.getDistance() ? activity.getDistance().getValue() : 0; }, 0)));
event.setPause(new data_pause_1.DataPause(event.getActivities().reduce(function (duration, activity) { return activity.getPause().getValue(); }, 0)));
//@todo add generate
return resolve(event);
});

@@ -140,0 +140,0 @@ };

import { StatsClassInterface } from './stats.class.interface';
import { IDClass } from '../id/id.abstract.class';
import { DataDuration } from '../data/data.duration';
import { DataDistance } from '../data/data.distance';
import { DataInterface } from '../data/data.interface';
import { DataPause } from '../data/data.pause';
export declare abstract class StatsClassAbstract extends IDClass implements StatsClassInterface {
stats: Map<string, DataInterface>;
getDistance(): DataDistance;
getDuration(): DataDuration;
getPause(): DataPause;
getStat(statType: string): DataInterface | void;

@@ -16,5 +12,3 @@ getStats(): Map<string, DataInterface>;

setDistance(distance: DataDistance): void;
setDuration(duration: DataDuration): void;
setPause(pause: DataPause): void;
addStat(stat: DataInterface): void;
}

@@ -14,5 +14,3 @@ "use strict";

var id_abstract_class_1 = require("../id/id.abstract.class");
var data_duration_1 = require("../data/data.duration");
var data_distance_1 = require("../data/data.distance");
var data_pause_1 = require("../data/data.pause");
var StatsClassAbstract = /** @class */ (function (_super) {

@@ -28,8 +26,2 @@ __extends(StatsClassAbstract, _super);

};
StatsClassAbstract.prototype.getDuration = function () {
return this.stats.get(data_duration_1.DataDuration.className);
};
StatsClassAbstract.prototype.getPause = function () {
return this.stats.get(data_pause_1.DataPause.className);
};
StatsClassAbstract.prototype.getStat = function (statType) {

@@ -47,8 +39,2 @@ return this.stats.get(statType);

};
StatsClassAbstract.prototype.setDuration = function (duration) {
this.stats.set(data_duration_1.DataDuration.className, duration);
};
StatsClassAbstract.prototype.setPause = function (pause) {
this.stats.set(data_pause_1.DataPause.className, pause);
};
StatsClassAbstract.prototype.addStat = function (stat) {

@@ -55,0 +41,0 @@ this.stats.set(stat.getClassName(), stat);

@@ -1,10 +0,6 @@

import { DataDuration } from '../data/data.duration';
import { DataDistance } from '../data/data.distance';
import { DataInterface } from '../data/data.interface';
import { DataPause } from '../data/data.pause';
import { IDClassInterface } from '../id/id.class.interface';
export interface StatsClassInterface extends IDClassInterface {
getDistance(): DataDistance;
getDuration(): DataDuration;
getPause(): DataPause;
getStat(statType: string): DataInterface | void;

@@ -14,5 +10,3 @@ getStats(): Map<string, DataInterface>;

setDistance(distance: DataDistance): void;
setDuration(duration: DataDuration): void;
setPause(pause: DataPause): void;
addStat(stat: DataInterface): void;
}
{
"name": "quantified-self-lib",
"version": "1.1.0",
"version": "1.1.1",
"description": "A Library to for processing GPX, TCX, FIT and JSON files from services such as Strava, Movescount, Garmin, Polar etc",

@@ -49,6 +49,6 @@ "keywords": [

"devDependencies": {
"@types/jest": "^23.1.6",
"@types/jest": "^23.3.0",
"jest": "^23.4.1",
"ts-jest": "^23.0.0",
"tslint": "^5.10.0",
"ts-jest": "^23.0.1",
"tslint": "^5.11.0",
"typescript": "^2.9.2"

@@ -55,0 +55,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc