Revize 0c31d12c
Přidáno uživatelem Petr Hlaváč před téměř 5 roky(ů)
.gitignore | ||
---|---|---|
4 | 4 |
cache |
5 | 5 |
.phpcs-cache |
6 | 6 |
.php_cs.cache |
7 |
database/ |
|
7 |
./database/
|
|
8 | 8 |
.idea |
9 | 9 |
dev-dump/ |
10 | 10 |
*.lock |
python-module/Utilities/Database/DatabaseDataLine.py | ||
---|---|---|
1 |
class DatabaseDataLine: |
|
2 |
|
|
3 |
def __init__(self, name, longitude, latitude, date, occurence): |
|
4 |
self.name = name |
|
5 |
self.latitude = latitude |
|
6 |
self.longitude = longitude |
|
7 |
self.date = date |
|
8 |
self.occurence = occurence |
|
9 |
|
|
10 |
def to_dictionary(self): |
|
11 |
return {"place": self.name, "x": self.longitude, "y": self.latitude, "number": self.occurence, "date": self.date} |
python-module/Utilities/Database/DatabaseLoader.py | ||
---|---|---|
1 |
from Utilities.Database import DatabaseDataLine |
|
2 |
import pymongo |
|
3 |
|
|
4 |
|
|
5 |
def get_data_from_file(filename, devices): |
|
6 |
f = open(filename, "r") |
|
7 |
|
|
8 |
date_dict = dict() |
|
9 |
|
|
10 |
for line in f: |
|
11 |
# remove \n |
|
12 |
line = line[:-1] |
|
13 |
# split by csv splitter ; |
|
14 |
|
|
15 |
csv_collum = line.split(";") |
|
16 |
|
|
17 |
name = csv_collum[0] |
|
18 |
occurence = csv_collum[1] |
|
19 |
date = csv_collum[2] |
|
20 |
|
|
21 |
date_without_hours = date[:-2] |
|
22 |
|
|
23 |
database_data_line = DatabaseDataLine.DatabaseDataLine(name, devices[name]["x"] |
|
24 |
, devices[name]["y"], date, occurence) |
|
25 |
|
|
26 |
if date_without_hours not in date_dict: |
|
27 |
date_dict[date_without_hours] = list() |
|
28 |
|
|
29 |
date_dict[date_without_hours].append(database_data_line.to_dictionary()) |
|
30 |
|
|
31 |
return date_dict |
|
32 |
|
|
33 |
|
|
34 |
def load_data_to_database(dataset_name, data_dic): |
|
35 |
myclient = pymongo.MongoClient("mongodb://localhost:27017/"); |
|
36 |
|
|
37 |
# Authenticating |
|
38 |
myclient.admin.authenticate('root', 'root'); |
|
39 |
|
|
40 |
# Database DATA |
|
41 |
mydb = myclient["DATA"] |
|
42 |
|
|
43 |
# Collection Datasets |
|
44 |
collection_datasets = mydb["DATASETS"] |
|
45 |
|
|
46 |
dataset_present = collection_datasets.find_one({}, {'name': dataset_name}) |
|
47 |
|
|
48 |
if dataset_present is None: |
|
49 |
collection_datasets.insert_one({'name': dataset_name}) |
|
50 |
|
|
51 |
for date in data_dic: |
|
52 |
dataset_collections = mydb[dataset_name] |
|
53 |
dataset_collections.insert_one({'name': dataset_name+date}) |
|
54 |
date_dataset = mydb[dataset_name + date] |
|
55 |
date_dataset.insert_many(data_dic[date]) |
Také k dispozici: Unified diff
Hotfix nepridani dat ze slozky Database