def run(self): schema = schemas.Sensor(many=True) ref = self.database.db.accelerometres.find( {'ref': str(self.params.uuid)}) self.data, errors = schema.dump(ref) x = [snap.get('x') for snap in self.data] y = [snap.get('y') for snap in self.data] z = [snap.get('z') for snap in self.data] nbBins = self.params.bins x = [{ 'r': snap.real, 'i': snap.imag } for snap in np.fft.fft(x, nbBins)] y = [{ 'r': snap.real, 'i': snap.imag } for snap in np.fft.fft(y, nbBins)] z = [{ 'r': snap.real, 'i': snap.imag } for snap in np.fft.fft(z, nbBins)] temp = {"accelerometres": []} for i in range(1, min(len(x), len(y), len(z))): value = {"x": x[i], "y": y[i], "z": z[i]} temp["accelerometres"].append(value) self.output.result = {"accelerometres": temp["accelerometres"]} return self.output
def run(self): """ Activity Tracker Algorithm Step 1 : Import the data from the database Step 2 : Calculate the magnetude of the data Step 3 : Calculate the difference of the new magnetude list Step 4 : Calculate the % of diff(magnetude) that is higher than a threshold :return: self.output """ schema = schemas.Sensor(many=True) ref = self.database.db.accelerometres.find( {'ref': ObjectId(self.params.uuid)}) acc, errors = schema.dump(ref) self.data = acc x = [ sqrt(snap.get('x')**2 + snap.get('y')**2 + snap.get('z')**2) for snap in self.data ] diff = numpy.diff(x) total = 0 for n in diff: if abs(n) > self.params.threshold: total = total + 1 self.output.result = 100 * total / len(diff) self.output.threshold = self.params.threshold self.output.maximum = max(diff) self.output.minimum = min(diff) self.output.size = len(diff) return self.output
def run(self): """ Algorithm du temps d'activité Étape 1 : Importer les données provenant de la base de données Étape 2 : Calculer la magnitude des données Étape 3 : Calculer la différence de la magnitude des données Étape 4 : Calcule le pourcentage de la différence de la magnitude qui dépasse le seuil donné en paramètre :return: self.output """ threshold = 100 schema = schemas.Sensor(many=True) ref = self.database.db.accelerometres.find({'ref': self.params.uuid}) acc, errors = schema.dump(ref) self.data = acc x = [sqrt(snap.get('x') ** 2 + snap.get('y') ** 2 + snap.get('z') ** 2) for snap in self.data] diff = numpy.diff(x) total = 0 for n in diff: if abs(n) > threshold: total = total + 1 self.output.result = 100*total/len(diff) self.output.threshold = threshold self.output.maximum = max(diff) self.output.minimum = min(diff) self.output.size = len(diff) self.output.execute_time = self.timer return self.output.result
def run(self): """ Algorithme pour un compteur de pas Étape 1 : Importer les données de l'enregistrement provenant de la base de données Étape 2 : Calculater la moyenne mobile sur les données Étape 3 : Identifier les sommets séparer par un certain intervale et une limite :return: Rien par défaut, mais self.ouput et quand même utile à retourner """ schema = schemas.Sensor(many=True) ref = self.database.db.accelerometres.find({'ref': str(self.params.uuid)}) data, errors = schema.dump(ref) if len(data)/2 < self.spacing : self.spacing = round(len(data)/2 - 1) filtereddata = self.moving_average(data) peaks = self.find_peaks(filtereddata,spacing = self.spacing,limit = 8250) # If you have imported matplotlib, you can decomment the following section. It block the cpu. #t = np.linspace(0, 1, len(filtereddata)) #plt.plot(t,filtereddata) #plt.plot(t[peaks],filtereddata[peaks],'ro') #plt.show() self.output.result = len(peaks) return self.output
def run(self): schema = schemas.Sensor(many=True) ref = self.database.db.accelerometres.find({'ref': ObjectId(self.params.uuid)}) self.data, errors = schema.dump(ref) x = np.array(self.data) y = np.fft(x) return y
def run(self): """ Coquille vide d'un algorithme Donne un exemple de la façon de charger des données provenant de la base de données :return: self.output """ schema = schemas.Sensor(many=True) ref = self.database.db.accelerometres.find( {'ref': str(self.params.uuid)}) self.data, errors = schema.dump(ref) #self.output Est l'endroit où votre résultats devrais être renvoyer. #Vous pouvez ajouter autant de sous-résultat tant que les résultat sont afficher dans le JSON et qu'ils ont un nom différent #EX : self.output.result1 = 1 # self.output.result2 = {"test":"Hello World"} return self.output
def run(self): """ Algorithme pour un compteur de pas Étape 1 : Importer les données de l'enregistrement provenant de la base de données Étape 2 : Calculater la moyenne mobile sur les données Étape 3 : Identifier les sommets séparer par un certain intervale et une limite :return: Rien par défaut, mais self.ouput et quand même utile à retourner """ schema = schemas.Sensor(many=True) ref = self.database.db.accelerometres.find({'ref': str(self.params.uuid)}) data, errors = schema.dump(ref) if len(data)/2 < self.spacing : self.spacing = round(len(data)/2 - 1) self.output.result = self.moving_average(data,self.spacing) return self.output
def run(self): """ Template Algorithm Show an example of how to load the data from the database :return: self.output """ schema = schemas.Sensor(many=True) ref = self.database.db.accelerometres.find( {'ref': str(self.params.uuid)}) self.data, errors = schema.dump(ref) filter = None if self.params.type == "passe-bas": filter = self.LowPass(float(self.params.cutoff), float(self.params.transition)) elif self.params.type == "passe-haut": filter = self.HighPass(float(self.params.cutoff), float(self.params.transition)) x = [snap.get('x') for snap in self.data] y = [snap.get('y') for snap in self.data] z = [snap.get('z') for snap in self.data] t = [snap.get('t') for snap in self.data] x = [snap for snap in filter.apply(x)] y = [snap for snap in filter.apply(y)] z = [snap for snap in filter.apply(z)] temp = {"accelerometres": []} for i in range(1, min(len(x), len(y), len(z), len(t))): value = {"x": x[i], "y": y[i], "z": z[i], "t": t[i]} temp["accelerometres"].append(value) self.output.result = {"accelerometres": temp["accelerometres"]} #self.output is were you return the result. #You can add as much subresult as you want, as long as the result is shown in JSON and that they have different name #EX : self.output.result1 = 1 # self.output.result2 = {"test":"Hello World"} return self.output