-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.py
More file actions
101 lines (83 loc) · 2.65 KB
/
examples.py
File metadata and controls
101 lines (83 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from clevermaps_sdk import sdk
# Your project_id (can be obtained from the url of the project or from the CleverMaps Shell)
project_id = ""
# Your access_token (https://clevermaps.docs.apiary.io/#reference/authentication)
access_token = ""
# CleverMaps SDK object initialization
cm_sdk = sdk.Sdk(access_token)
# Call some global workspace methods
print(cm_sdk.projects.projects.list_projects())
print(cm_sdk.projects.project.get_project_by_id(project_id))
# Open specific project and work with data or metadata
cm_project = cm_sdk.open(project_id)
# Query data and metrics
query_json = {
"properties": [
"obec_dwh.nazev",
"poi_dwh.type_name",
"poi_dwh.subtype_name",
],
"metrics": [
"pois_sum_metric",
"pois_count_metric"
],
"filter_by": [
{
"property": "obec_dwh.nazev",
"operator": "eq",
"value": "Brno"
},
{
"property": "poi_dwh.subtype_name",
"operator": "in",
"value": ["cafe", "restaurant"]
}
]
}
# Print query results as json
print(cm_project.query(query_json))
# Export query results to the file
export_json = {
'query': query_json,
'filename': 'test.csv',
'format': 'csv'
}
export_result = cm_project.export_to_csv(export_json)
with open('export.csv', 'w') as outf:
outf.write(export_result)
# Get available datasets for the metric
print(cm_project.get_available_datasets('pois_count_metric'))
# Get property values of the column
print(cm_project.get_property_values("poi_dwh.subtype_name"))
# List all metrics in the project
print(cm_project.metadata.metrics.list_metrics())
# List all datasets in the project
print(cm_project.metadata.datasets.list_datasets())
# Fulltext search in dataset
print(cm_project.fulltext_search('poi_dwh', 'Albert'))
# Upload CSV file to CleverMaps
csv_options = {
"header": True,
"separator": ",",
"quote": "\"",
"escape": "\\"
}
with open('./data/poi_dwh.csv', 'rb') as f:
print(cm_project.upload_data('poi_dwh', 'full', f, csv_options))
# Dump CSV file from CleverMaps
dump_result = cm_project.dump_data('poi_dwh')
with open('./data/poi_dwh_dump.csv', 'w') as outf:
outf.write(dump_result)
# Update metadata
metric_update_json = {
'description': 'New description'
}
print(cm_project.metadata.metrics.update_metric('pois_sum_metric', metric_update_json))
view_update_json = {
'description': 'New description'
}
print(cm_project.metadata.views.update_view('exposure_index_view', view_update_json))
dataset_update_json = {
'description': 'New description'
}
print(cm_project.metadata.datasets.update_dataset('poi_dwh', dataset_update_json))