{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "import pandas as pd\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import re\n", "\n", "class state_gen_old:\n", " \"\"\"\"\"\"\n", " def __init__(self,pattern_start,pattern_stop,null_state=\"Null\"):\n", " self.previous = null_state\n", " self.null_state=null_state\n", " self.pattern_start=pattern_start\n", " self.pattern_stop=pattern_stop\n", " \n", " def __call__(self,actual):\n", " \n", " if(not(pd.isnull(actual))):\n", " \n", " #Start condition\n", " if((re.search(self.pattern_start,actual))!=None):\n", " self.previous=actual\n", " \n", " #End Condition\n", " elif((re.search(self.pattern_stop,actual))!=None):\n", " self.previous = self.null_state\n", " \n", " return self.previous\n", " \n", " \n", "class state_gen_new:\n", " \"\"\"\"\"\"\n", " def __init__(self,pattern_start,pattern_stop,split = False,null_state=\"Null\"):\n", " self.previous = null_state\n", " self.null_state = null_state\n", " self.pattern_start = pattern_start\n", " self.pattern_stop = pattern_stop\n", " self.split = split\n", " \n", " def process_state(self,state):\n", " if (self.split):\n", " #Keep the root of the state (eg. _Y6014 IntervalStart --> _Y6014)\n", " state = state.split()[0]\n", " return state\n", "\n", " def __call__(self,actual):\n", " if(not(pd.isnull(actual))):\n", " #Start condition\n", " if((re.search(self.pattern_start,actual))!=None):\n", " self.previous = self.process_state(actual)\n", " \n", " #End Condition\n", " elif((re.search(self.pattern_stop,actual))!=None):\n", " self.previous = self.null_state\n", " \n", " return self.previous" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "path_old= r\"C:\\Users\\jeuux\\Desktop\\Carrera\\MoAI\\TFM\\AnnotatedData\\Accelerometer_Data\\Participants\\0404b\\CompleteData\\segments_data.npy\"\n", "path_new = r\"C:\\Users\\jeuux\\Desktop\\Carrera\\MoAI\\TFM\\AnnotatedData\\FinalDatasets\\Participants\\0404b\\FullDataset\\segments_data.npy\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# # df_old = pd.read_csv(path_old)\n", "# df_old = pd.read_csv(path_new)\n", "# df_new = pd.read_csv(path_new)\n", "targets_old = np.load(path_old)\n", "targets_new = np.load(path_new)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "targets_old[0] == targets_new[0]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "targets_old == targets_new" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "##get targets and valid intervals\n", "generator_target_old=state_gen_old(\"AG\",\"Behaviour End\")\n", "df_old[\"target\"]=df_old[\"Event\"].apply(lambda event: generator_target_old(event))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df_old.target.value_counts()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "##get targets and valid intervals\n", "generator_target_new=state_gen_new(\"AG\",\"Behaviour End\")\n", "df_new[\"target\"]=df_new[\"Event\"].apply(lambda event: generator_target_new(event))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df_new.target.value_counts() ==df_old.target.value_counts()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df_new[df_new[\"Recording timestamp\"]==0]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df0_path = r\"C:\\Users\\jeuux\\Desktop\\Carrera\\MoAI\\TFM\\AnnotatedData\\Accelerometer_Data\\Participants\\0705b\\CompleteData\\CompleteData_raw_0705b.csv\"\n", "df1_path = r\"C:\\Users\\jeuux\\Desktop\\Carrera\\MoAI\\TFM\\AnnotatedData\\FinalDatasets\\Participants\\0705b\\FullDataset\\FullDataset_raw_0705b.csv\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df0 = pd.read_csv(df0_path)\n", "df1 = pd.read_csv(df1_path)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df0[df0[\"Recording timestamp\"]==0]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df1[df1[\"Recording timestamp\"]==0]" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.6" } }, "nbformat": 4, "nbformat_minor": 4 }