Skip to content

Commit c8fe166

Browse files
authoredMay 10, 2018
Update README.md
1 parent e543342 commit c8fe166

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
 

‎README.md

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Data Graphing Project
2+
3+
## Task description
4+
5+
I needs to create .jpg/.png graphs images from data in postges, using Django’s management command. The Django models and sample data are below (the actual data is truncated; just a subset is shown). Please review the data before reading any further.
6+
7+
We will build two graphs per location. The first graph will use avg_resp_proxy data and the second will use avg_resp_direct data. Based on the date specified, the code should query measurements for the amount of days requested, for each proxy. If there are less days in the database than requested, the graph should only use the dates available. To explain the X and Y columns, the Y column is milliseconds and the X columns are dates (although the graph below shows time, we will only use dates). Although the timestamps in the database have more than 2 decimal points, these can be rounded, as shown in the example graph below:
8+
9+
# Some minor changes
10+
11+
1. In Measurement location field changed to ForeignKey field to allow store more than one measure per location
12+
13+
```
14+
class Measurement(models.Model):
15+
location = models.ForeignKey('locations.Location', on_delete=models.CASCADE)
16+
proxy = models.CharField(('proxy'), max_length=10)
17+
avg_resp_proxy = models.CharField(('avg_resp_proxy'), max_length=20)
18+
avg_avail_proxy = models.CharField(('Average available proxy'), max_length=20)
19+
avg_resp_direct = models.CharField(('avg_resp_direct'), max_length=20)
20+
avg_avail_direct = models.CharField(('Average available direct'), max_length=20)
21+
date = models.DateField(auto_now=True)
22+
23+
class Meta:
24+
ordering = ('date',)
25+
26+
def __str__(self):
27+
return '{} - {}'.format(self.date, self.location.city)
28+
```
29+
30+
2. Using matplotlib instead https://plot.ly/python/. In this task only need to create static files with management
31+
commands, so using plot.ly in this case will be overhead.
32+
33+
3. If only one measure available - drawing only one dot, if none data available - image didnt create, if more one data created - drawing simple graph.
34+
35+
# Installation
36+
37+
We use project in docker container for fast installation. So you need docker and doccker-compose packages installed.
38+
Please refer https://docs.docker.com/install/linux/docker-ce/ubuntu/ and https://docs.docker.com/compose/install/ for installation procedures.
39+
40+
Copy env_default file to .env and edit parameters.
41+
```
42+
cp env_defaul .env
43+
nano .env
44+
```
45+
46+
Build image
47+
```
48+
docker-compose build
49+
```
50+
51+
Start project with
52+
```
53+
docker-compose up -d
54+
```
55+
56+
Docker starts two containers - graphic-web and graphic-db
57+
58+
# Load initial data
59+
Initial test data can be loaded with:
60+
61+
```
62+
cat graphic.sql | docker exec --user=postgres -i graphic-db psql -U postgres
63+
```
64+
65+
# Change password for admin
66+
67+
```
68+
$ docker exec -ti graphic-web python manage.py changepassword admin
69+
Changing password for user 'admin'
70+
Password:
71+
Password (again):
72+
Password changed successfully for user 'admin'
73+
```
74+
75+
76+
# CLI syntax
77+
78+
Example of creating needed images:
79+
Data in format dd/mm/yyyy
80+
```
81+
docker exec -ti graphic-web python manage.py build-images --date=02/03/2018 --days=4
82+
```
83+
By default graphic images created in ../data/ directory. You can change location in .env in DATA_DIR variable.

0 commit comments

Comments
 (0)
Please sign in to comment.