Commit f4210851 authored by Boteju W.J.M.'s avatar Boteju W.J.M.

10/09

parent 39d9e64e
Pipeline #1723 failed with stages
......@@ -33,7 +33,7 @@
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$USER_HOME$/anaconda3/Lib/site-packages/pymongo/mongo_client.py" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="node.js.detected.package.eslint" value="true" />
<property name="node.js.detected.package.tslint" value="true" />
<property name="node.js.path.for.package.eslint" value="project" />
......@@ -43,6 +43,9 @@
<property name="settings.editor.selected.configurable" value="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" />
</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="C:\Research\DogBehaviouralSystem\DogBehaviouralSystem\Django\WalkingPatternRecognition" />
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="C:\Research\DogBehaviouralSystem\DogBehaviouralSystem\Django\WalkingPatternRecognition\WalkingPatternRecognition" />
<recent name="C:\Research\DogBehaviouralSystem\DogBehaviouralSystem\Django\WalkingPatternRecognition\mobileapp" />
......@@ -201,10 +204,11 @@
</state>
<state x="-162" y="98" key="SettingsEditor/0.0.1536.824/1920.0.1920.1040@0.0.1536.824" timestamp="1597320661738" />
<state x="2383" y="166" key="SettingsEditor/0.0.1536.824/1920.0.1920.1040@1920.0.1920.1040" timestamp="1597053750811" />
<state x="2601" y="261" width="540" height="524" key="StructurePopup" timestamp="1600149249330">
<screen x="1920" y="0" width="1920" height="1040" />
<state x="545" y="207" width="534" height="416" key="StructurePopup" timestamp="1600834193918">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="2601" y="261" width="540" height="524" key="StructurePopup/0.0.1536.824/1920.0.1920.1040@1920.0.1920.1040" timestamp="1600149249330" />
<state x="545" y="207" width="534" height="416" key="StructurePopup/0.0.1536.824@0.0.1536.824" timestamp="1600834193918" />
<state x="477" y="241" key="com.intellij.ide.util.TipDialog" timestamp="1595569410321">
<screen x="0" y="0" width="1536" height="824" />
</state>
......
StartTime,EndTime,Date,Activity
2020-09-24 00:38:24.027610,2020-10-08 17:01:19.787791,2020-10-08 17:01:19.787791,3
2020-09-24 00:38:24.027610,2020-10-08 17:01:19.787791,2020-10-08 17:01:19.787791,3
2020-09-24 00:38:24.027610,2020-10-08 17:01:19.787791,2020-10-08 17:01:19.787791,3
2020-10-08 17:12:00.933364,2020-10-08 17:14:27.715634,2020-10-08 17:14:27.715634,3
2020-10-08 17:14:29.660483,2020-10-08 17:14:58.183088,2020-10-08 17:14:58.183088,1
2020-10-08 17:15:02.305532,2020-10-08 17:15:32.210587,2020-10-08 17:15:32.210587,1
2020-10-08 17:15:34.660100,2020-10-08 17:16:03.652303,2020-10-08 17:16:03.652303,3
2020-10-08 17:16:05.656790,2020-10-08 17:19:26.484795,2020-10-08 17:19:26.484795,3
2020-10-08 17:19:30.439883,2020-10-08 17:22:51.428927,2020-10-08 17:22:51.428927,3
2020-10-08 17:32:56.456390,2020-10-08 17:34:01.589244,2020-10-08 17:34:01.589244,3
17,2020-10-08 17:46:50.246984,2020-10-08 17:46:50.246984,3
AccXmin,AccYmin,AccZmin,AccXmax,AccYmax,AccZmax,AccXmean,AccYmean,AccZmean,GyrXmin,GyrYmin,GyrZmin,GyrXmax,GyrYmax,GyrZmax,GyrXmean,GyrYmean,GyrZmean,StartTime,EndTime
0.27,-2.0,-1.56,2.0,-1.06,0.68,1.1260000000000001,-1.7216666666666667,-0.48200000000000015,-179.27,-103.43,-126.21,118.6,172.2,132.02,-16.891999999999996,21.392999999999997,-14.823333333333329,2020-10-07 21:25:34.480018,2020-10-07 21:26:34.454792
0.28,-2.0,-1.51,1.92,-0.79,0.84,0.9843333333333334,-1.693,-0.46266666666666684,-90.35,-163.44,-133.0,208.27,250.13,204.45,30.510333333333335,18.53100000000001,4.710666666666668,2020-10-07 21:26:40.246292,2020-10-07 21:27:36.457781
-1.48,-2.0,-2.0,2.0,1.39,2.0,0.7333333333333335,-1.1643333333333332,-0.12766666666666668,-154.02,-250.14,-109.05,250.13,221.15,118.76,-3.1066666666666674,-22.333333333333332,6.58033333333333,2020-10-07 21:27:40.446966,2020-10-07 21:28:48.459612
-0.8,-2.0,-2.0,2.0,0.89,2.0,0.8023333333333333,-0.7633333333333334,0.08366666666666665,-100.68,-226.79,-65.86,190.92,250.13,145.5,-1.1676666666666695,29.762999999999995,5.359,2020-10-07 21:28:52.455488,2020-10-07 21:29:54.480697
-0.43,-2.0,-2.0,2.0,2.0,1.76,0.945,-0.8386666666666668,0.008999999999999985,-205.78,-250.14,-168.67,174.48,198.21,129.9,-1.7920000000000043,-68.14900000000002,11.611666666666663,2020-10-07 21:29:58.471774,2020-10-07 21:31:00.487873
AccXmin,AccYmin,AccZmin,AccXmax,AccYmax,AccZmax,AccXmean,AccYmean,AccZmean,GyrXmin,GyrYmin,GyrZmin,GyrXmax,GyrYmax,GyrZmax,GyrXmean,GyrYmean,GyrZmean,StartTime,EndTime
1.29,-2.0,-0.39,2.0,-1.79,0.06,1.6373333333333333,-1.9626666666666666,-0.16933333333333334,-99.73,-55.16,-73.8,141.04,45.04,60.31,3.9366666666666674,-4.107,-0.6590000000000001,2020-10-07 21:08:30.304304,2020-10-07 21:09:28.196655
0.57,-2.0,-1.27,1.39,-1.95,-0.63,1.0646666666666669,-1.997,-0.8743333333333331,-39.16,-37.98,-134.39,64.01,37.15,87.87,-1.1113333333333337,-5.086333333333332,-4.315333333333332,2020-10-07 21:09:32.198093,2020-10-07 21:10:32.198199
0.7,-2.0,-1.49,1.46,-1.93,-0.58,1.0473333333333334,-1.996,-0.9093333333333332,-51.63,-35.78,-142.61,32.88,83.82,62.39,-5.182666666666664,4.522333333333333,-3.149,2020-10-07 21:10:36.202928,2020-10-07 21:11:36.214717
-0.4,-2.0,-1.3,1.82,-1.81,-0.46,0.9716666666666669,-1.971666666666667,-0.8623333333333333,-136.37,-169.94,-130.72,32.3,46.02,147.41,-4.960333333333334,-8.545666666666666,-5.7730000000000015,2020-10-07 21:11:40.205772,2020-10-07 21:12:38.212620
0.85,-2.0,-1.22,1.32,-1.78,-0.59,1.0666666666666669,-1.9309999999999996,-0.8776666666666665,-55.24,-49.32,-36.3,34.85,40.34,97.03,-7.955333333333334,2.4200000000000004,5.284666666666666,2020-10-07 21:12:42.206363,2020-10-07 21:13:44.212033
0.8,-2.0,-1.22,1.37,-1.7,-0.59,1.0793333333333333,-1.9406666666666665,-0.8893333333333332,-60.15,-42.93,-115.36,93.99,63.91,73.37,-11.653333333333334,6.936666666666666,-5.461666666666667,2020-10-07 21:13:48.194591,2020-10-07 21:14:50.193790
0.28,-2.0,-1.56,1.36,-1.64,-0.26,0.7526666666666666,-1.9179999999999997,-0.9866666666666665,-75.72,-64.64,-168.53,101.87,131.71,86.18,-7.472666666666668,15.668333333333335,-11.32,2020-10-07 21:14:54.207308,2020-10-07 21:15:52.203123
0.51,-2.0,-1.64,1.29,-1.55,-0.49,0.8876666666666667,-1.885,-0.9080000000000003,-88.73,-86.14,-121.08,99.76,95.05,106.27,-12.50266666666667,12.678666666666667,9.46733333333333,2020-10-07 21:15:56.199380,2020-10-07 21:16:56.216994
timestamp,accelerometer_X,accelerometer_Y,accelerometer_Z,gyroscope_X,gyroscope_Y,gyroscope_Z
2020-09-20 23:26:41.953180,-0.00,-0.00,-0.00,-0.01,-0.01,-0.01
2020-09-20 23:26:43.892551,-0.00,-0.00,-0.00,-0.01,-0.01,-0.01
2020-09-20 23:26:45.905631,-0.00,-0.00,-0.00,-0.01,-0.01,-0.01
2020-09-20 23:26:47.906413,-0.00,-0.00,-0.00,-0.01,-0.01,-0.01
2020-09-20 23:26:49.894551,-0.00,-0.00,-0.00,-0.01,-0.01,-0.01
2020-09-20 23:26:51.896948,-0.00,-0.00,-0.00,-0.01,-0.01,-0.01
2020-09-20 23:26:53.895052,-0.00,-0.00,-0.00,-0.01,-0.01,-0.01
2020-09-20 23:26:55.896255,-0.00,-0.00,-0.00,-0.01,-0.01,-0.01
2020-09-20 23:26:57.895174,-0.00,-0.00,-0.00,-0.01,-0.01,-0.01
2020-09-20 23:26:59.894743,-0.00,-0.00,-0.00,-0.01,-0.01,-0.01
2020-09-20 23:27:01.892516,-0.00,-0.00,-0.00,-0.01,-0.01,-0.01
2020-09-20 23:27:03.905684,-0.00,-0.00,-0.00,-0.01,-0.01,-0.01
2020-09-20 23:27:06.089525,-0.00,-0.00,-0.00,-0.01,-0.01,-0.01
2020-09-20 23:27:07.915467,-0.00,-0.00,-0.00,-0.01,-0.01,-0.01
2020-09-20 23:27:09.947959,-0.00,-0.00,-0.00,-0.01,-0.01,-0.01
2020-09-20 23:27:11.895715,-0.00,-0.00,-0.00,-0.01,-0.01,-0.01
2020-09-20 23:27:13.902559,-0.00,-0.00,-0.00,-0.01,-0.01,-0.01
2020-10-08 17:50:17.639840,1.66,-1.93,-0.21,-8.60,0.91,3.30
2020-10-08 17:50:19.643738,1.66,-1.93,-0.21,-8.66,0.71,3.42
2020-10-08 17:50:21.650621,1.66,-1.94,-0.20,-8.55,0.80,3.53
2020-10-08 17:50:23.640301,1.66,-1.93,-0.20,-8.56,0.69,3.50
2020-10-08 17:50:25.640222,1.66,-1.93,-0.20,-8.66,0.82,3.49
2020-10-08 17:50:27.650271,1.66,-1.93,-0.21,-8.54,0.76,3.45
timestamp,accelerometer_X,accelerometer_Y,accelerometer_Z,gyroscope_X,gyroscope_Y,gyroscope_Z
2020-09-16 18:19:34.220893,0.05,0.00,0.00,0.00,0.00,0.00
2020-09-16 18:19:36.217454,0.05,0.00,0.00,0.00,0.00,0.00
2020-09-16 18:19:38.206760,0.05,0.00,0.00,0.00,0.00,0.00
2020-09-16 18:19:40.202189,0.02,0.00,0.00,0.00,0.00,0.00
2020-09-16 18:19:42.205321,0.02,0.00,0.00,0.00,0.00,0.00
2020-10-08 14:11:15.153998,1.65,-1.96,-0.17,-8.73,1.00,3.54
2020-10-08 14:11:17.196000,1.65,-1.69,-0.21,-66.31,-16.92,-27.58
2020-10-08 14:11:19.195747,1.66,-1.94,-0.20,8.22,-0.27,-1.45
2020-10-08 14:11:21.143897,1.66,-1.91,-0.18,-8.42,0.67,3.50
2020-10-08 14:11:23.158657,1.66,-1.92,-0.19,-8.58,0.84,3.67
timestamp,accelerometer_X,accelerometer_Y,accelerometer_Z,gyroscope_X,gyroscope_Y,gyroscope_Z
2020-10-07 21:31:04.462506,0.81,-1.22,0.30,146.15,-149.11,-103.11
2020-10-07 21:31:06.459787,0.44,-1.84,-0.92,21.79,-1.71,-87.03
2020-10-07 21:31:08.463680,0.93,-2.00,-0.95,1.77,7.95,10.51
2020-10-07 21:31:10.460064,1.06,-2.00,-0.89,-9.28,6.11,3.95
2020-10-07 21:31:12.444541,1.07,-2.00,-0.90,-9.08,1.49,4.15
2020-10-07 21:31:14.438308,1.55,-2.00,-0.74,-11.98,16.53,131.53
2020-10-07 21:31:16.453118,1.44,-1.65,-0.27,250.13,-33.13,-179.40
2020-10-07 21:31:18.478286,1.65,-2.00,-0.30,-168.40,-13.96,111.17
2020-10-07 21:31:20.455693,1.38,-2.00,-0.69,0.34,9.67,38.86
2020-10-07 21:31:22.454399,1.40,-1.81,-0.30,-125.21,-15.67,60.08
2020-10-07 21:31:24.451804,0.97,-2.00,-0.20,-62.45,-33.55,128.02
2020-10-07 21:31:26.444271,1.65,-2.00,0.12,12.29,37.05,38.15
2020-10-07 21:31:28.441073,1.67,-1.93,-0.12,-8.73,0.71,3.28
2020-10-07 21:31:30.438010,1.67,-1.92,-0.12,-8.63,0.90,3.50
2020-10-07 21:31:32.470579,1.68,-1.93,-0.12,-8.61,0.81,3.66
2020-10-07 21:31:34.469448,1.68,-1.92,-0.12,-8.56,0.70,3.42
2020-10-07 21:31:36.459007,1.68,-1.93,-0.11,-8.52,0.34,3.46
timestamp,accelerometer_X,accelerometer_Y,accelerometer_Z,gyroscope_X,gyroscope_Y,gyroscope_Z
2020-10-07 21:17:02.248393,0.84,-1.88,-1.54,-10.08,-40.27,30.66
2020-10-07 21:17:04.191616,0.94,-2.00,-1.00,-31.69,-35.68,88.81
2020-10-07 21:17:06.199906,0.57,-1.80,-0.71,-8.39,18.92,17.91
2020-10-07 21:17:08.209362,0.80,-2.00,-0.85,4.69,13.13,17.70
2020-10-07 21:17:10.237936,0.73,-1.91,-0.65,-50.95,-91.33,-4.47
2020-10-07 21:17:12.196930,0.99,-1.43,-0.82,-20.52,24.75,28.52
......@@ -28,7 +28,7 @@ SECRET_KEY = '^^46u_fc$#)x5ji*s#l3p6igr9*6fwknxevip$ozw8#-m=*#f0'
DEBUG = True
ALLOWED_HOSTS = ['192.168.1.49', 'localhost', '127.0.0.1']
ALLOWED_HOSTS = ['192.168.1.3', 'localhost', '127.0.0.1']
CORS_ORIGIN_ALLOW_ALL = False
......@@ -168,3 +168,5 @@ STATICFILES_DIRS = [
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# Generated by Django 3.0.5 on 2020-10-08 18:19
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import djongo.models.fields
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('mobileapp', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Breed',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=30, null=True)),
('slug', models.CharField(max_length=20, null=True)),
('restingMinutes', djongo.models.fields.JSONField(blank=True, default=list, null=True)),
('activityPerDay', models.IntegerField(null=True)),
('walkPerWeek', models.IntegerField(null=True)),
],
),
migrations.AddField(
model_name='dog',
name='imageUrl',
field=models.CharField(default='https://via.placeholder.com/150', max_length=500),
preserve_default=False,
),
migrations.CreateModel(
name='DogStatus',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date', models.DateField(default=django.utils.timezone.now)),
('activity', models.IntegerField(null=True)),
('status', models.CharField(max_length=25, null=True)),
('dog', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='mobileapp.Dog')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
# Generated by Django 3.0.5 on 2020-10-08 18:20
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('mobileapp', '0002_auto_20201008_1819'),
]
operations = [
migrations.CreateModel(
name='MotionActivity',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date', models.DateField(default=django.utils.timezone.now)),
('time', models.DateTimeField()),
('hour', models.IntegerField(null=True)),
('activity', models.IntegerField(null=True)),
('dog', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='mobileapp.Dog')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
......@@ -16,6 +16,7 @@ class Dog(models.Model):
breed = models.CharField(max_length=10)
gender = models.CharField(max_length=1, choices=GENDER_TYPES)
user = models.ForeignKey(User, on_delete=models.CASCADE)
imageUrl = models.CharField(max_length=500)
def __str__(self):
return self.name
......@@ -48,6 +49,7 @@ class MotionActivity(models.Model):
dog = models.ForeignKey(Dog, on_delete=models.CASCADE)
date = models.DateField(default=django.utils.timezone.now)
time = models.DateTimeField()
hour = models.IntegerField(null=True)
activity = models.IntegerField(null=True)
def __str__(self):
......
from rest_framework import serializers
from rest_framework.validators import UniqueTogetherValidator
from django.contrib.auth.models import User
from .models import Dog, MotionActivityPerDay, Activity, MotionActivity, DogStatus, Breed
from .models import Dog, MotionActivityPerDay, Activity,MotionActivity, DogStatus, Breed
class UserSerializer(serializers.ModelSerializer):
......@@ -31,7 +31,7 @@ class DogSerializer(serializers.ModelSerializer):
class Meta:
model = Dog
fields = ('id', 'name', 'birthday', 'breed', 'gender', 'user')
fields = ('id', 'name', 'birthday', 'breed', 'gender', 'user', 'imageUrl')
class ActivitySerializer(serializers.ModelSerializer):
......@@ -51,7 +51,7 @@ class MotionActivitySerializer(serializers.ModelSerializer):
class Meta:
model = MotionActivity
fields = ('user_id', 'dog_id', 'date', 'time', 'activity')
fields = ('user_id', 'dog_id', 'date', 'time', 'hour', 'activity')
class DogStatusSerializer(serializers.ModelSerializer):
......
......@@ -45,6 +45,8 @@ urlpatterns = [
# getting the readings
path('readings', views.readings),
path('trainingReadings', views.trainingReadings)
path('trainingReadings', views.trainingReadings),
path('endOfEachDay', views.endOfEachDay),
path('compare', views.compare)
]
......@@ -14,9 +14,9 @@ from rest_framework.decorators import api_view, permission_classes
from rest_framework.permissions import IsAuthenticated, IsAdminUser
from rest_framework.response import Response
from rest_framework.views import APIView
from .models import Dog, MotionActivityPerDay, Activity, MotionActivity, Breed, DogStatus
from .serializers import DogSerializer, MotionActivityPerDaySerializer, ActivitySerializer, MotionActivitySerializer, \
BreedSerializer, DogStatusSerializer
from .models import Dog, MotionActivityPerDay, Activity, Breed, DogStatus, MotionActivity
from .serializers import DogSerializer, MotionActivityPerDaySerializer, ActivitySerializer,BreedSerializer, \
DogStatusSerializer,MotionActivitySerializer
from .serializers import UserSerializer
from datetime import datetime
import calendar
......@@ -102,7 +102,8 @@ def add_DogProfile(request):
birthday=payload["birthday"],
breed=payload["breed"],
gender=payload["gender"],
user=user
user=user,
imageUrl= payload['imageUrl']
)
serializer = DogSerializer(dog)
return JsonResponse({'dog': serializer.data}, safe=False, status=status.HTTP_201_CREATED)
......@@ -288,9 +289,9 @@ def getTotalMinutesPerDay(request):
@permission_classes([IsAuthenticated])
def getTotalMinutesPerHour(request):
payload = json.loads(request.body)
minutes = MotionActivityPerDay.objects.filter(activity_id=payload['activity_id'], dog_id=payload['dog_id'],
date=payload['date'], )
serializer = MotionActivityPerDaySerializer(minutes, many=True)
minutes = MotionActivity.objects.filter(activity_id=payload['activity_id'], dog_id=payload['dog_id'],
date=payload['date'], hour=payload['hour'])
serializer = MotionActivitySerializer(minutes, many=True)
return JsonResponse({'minutes per hour': len(serializer.data)}, safe=False, status=status.HTTP_200_OK)
......@@ -613,7 +614,7 @@ def readings(request):
def getReadings():
ReadingsArray = []
responseObtained = requests.get('http://192.168.1.6/getReadings')
responseObtained = requests.get('http://192.168.1.5/getReadings')
# if(responseObtained):
# print("Successfully Obtaining readings from ... http://192.168.1.6/getReadings")
......@@ -695,8 +696,8 @@ class Main:
break
i = i + 30
# Start a scheduler to get the activity count at the end of the day
endOfTheDay()
# # Start a scheduler to get the activity count at the end of the day
# end()
class Data:
......@@ -876,6 +877,7 @@ class FeatureExtraction:
return feature
def getFeatureSingle(self, list):
print("In")
d = GetData(list)
X = d.getAccX(list)
Y = d.getAccY(list)
......@@ -884,7 +886,7 @@ class FeatureExtraction:
fe = FeatureExtraction(list)
feature = [fe.MinimumPeak(X), fe.MinimumPeak(Y), fe.MinimumPeak(Z), fe.MaximumPeak(X), fe.MaximumPeak(Y),
fe.MaximumPeak(Z), fe.Mean(X), fe.Mean(Y), fe.Mean(Z), times[0], times[1]]
print("Feature Vector \n", feature, "\n\n")
print("Small Feature Vector \n", feature, "\n\n")
return feature
......@@ -917,7 +919,7 @@ class ReadData:
class Test:
data = ''
activity = ''
def __init__(self, data):
self.data = data
with open("FeatureVectorTest.csv", 'r') as f:
......@@ -950,21 +952,27 @@ class Test:
if activityPrediction == 2:
activity = 'run'
print("PREDICTION ---->", activity, "-", activityPrediction, "\n\n")
print("PREDICTION ---->", activityPrediction, "\n\n")
times = StartTime.split(" ")
time_object = datetime.strptime(times[1], '%H:%M:%S.%f').time()
print(time_object.hour)
hour = time_object.hour
# date = datetime.utcnow().strftime("%Y-%m-%d")
# ConvertedDate = datetime.strptime(date, "%Y-%m-%d").date()
ConvertedDate = datetime.now()
date = datetime.utcnow().strftime("%Y-%m-%d")
ConvertedDate = datetime.strptime(date, "%Y-%m-%d").date()
# ConvertedDate = datetime.now()
motion = MotionActivity.objects.create(
user_id=1,
dog_id=1,
date=ConvertedDate,
time=StartTime,
hour = hour,
activity=activityPrediction
)
MotionActivitySerializer(motion)
ActivityArray.append(StartTime)
ActivityArray.append(EndTime)
ActivityArray.append(Date)
......@@ -992,14 +1000,21 @@ class Dictionary:
# ACTION AT THE END OF THE DAY
def getBreedData():
breedData = Dog.objects.all()
serializer = DogSerializer(breedData, many=False)
return Response(serializer.data)
def endOfEachDay(request):
payload = json.loads(request.body)
breed = payload['breed']
dog = payload['dog_id']
sched = BackgroundScheduler()
sched.add_job(endOfTheDay(breed, dog), 'interval', days=1)
sched.start()
return JsonResponse({'data': "Comparison at the End of the Day"}, safe=False, status=status.HTTP_201_CREATED)
def endOfTheDay():
print("At the End of the day...")
@api_view(["POST"])
def endOfTheDay(breed, dog):
print("At the End of the day...", datetime.now())
d1 = Data('DogData.csv')
data1 = d1.ReadData()
r = ReadData(data1)
......@@ -1016,7 +1031,7 @@ def endOfTheDay():
runMinutes = result[2]
# Compare the Breed Data
compareBreedData('German Shepherd', walkMinutes, runMinutes)
compareBreedData(breed, walkMinutes, runMinutes)
# Add the final results to the Motion Activity Per Day table
......@@ -1062,6 +1077,7 @@ def endOfTheDay():
for line in f:
f1.close()
append_list_as_row('DogData.csv', ['StartTime', 'EndTime', 'Date', 'Activity'])
return JsonResponse({'data': "Data obtained"}, safe=False, status=status.HTTP_201_CREATED)
def compareBreedData(breed, walkingMinutes, runningMinutes):
......@@ -1107,6 +1123,39 @@ def getBreedActivityData(breed):
return value
@api_view(["POST"])
def compare(request):
payload = json.loads(request.body)
breed = payload['breed']
ActivityMinutes = payload['time']
totalActivityMinutes, breedActivityMinutes = 0, 0
print("Now comparing " + breed)
activityStatusOfTheDog = ''
breedActivityMinutes = getBreedActivityData(breed)
totalActivityMinutes = ActivityMinutes
halfValue = breedActivityMinutes/2
print(halfValue)
print(ActivityMinutes)
if totalActivityMinutes > breedActivityMinutes:
print("Activity level is high")
activityStatusOfTheDog = 'high'
elif totalActivityMinutes < halfValue:
print("The actual activity level of the dog is : " + str(breedActivityMinutes) + " minutes")
print("But the current activity level of the dog is " + str(totalActivityMinutes) + " minutes")
print("Therefore .. Activity level is low")
activityStatusOfTheDog = 'low'
elif (totalActivityMinutes <= breedActivityMinutes) and (totalActivityMinutes >= halfValue):
print("Activity level is equal")
activityStatusOfTheDog = 'active'
# Add the status to the Dog Status Table
ConvertedDate = datetime.now()
return JsonResponse({'status': activityStatusOfTheDog}, safe=False, status=status.HTTP_201_CREATED)
# TRAINING READINGS
def trainingReadings(request):
......@@ -1121,7 +1170,7 @@ def trainingReadings(request):
def getTrainingReadings():
ReadingsArray = []
responseObtained = requests.get('http://192.168.1.36/getReadings')
responseObtained = requests.get('http://192.168.1.5/getReadings')
result = responseObtained.text
Array = result.split(",")
length = len(Array)
......
alabaster==0.7.12
amqp==1.4.9
anaconda-client==1.7.2
anaconda-navigator==1.9.12
anaconda-project==0.8.3
ansicon==1.89.0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment