-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathClient.py
More file actions
140 lines (122 loc) · 5.53 KB
/
Client.py
File metadata and controls
140 lines (122 loc) · 5.53 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
'''
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
******************************************************************************
Client.py
OpenSILEX
Copyright © INRAE 2021
Creation date: 22 April, 2021
Contact: arnaud.charleroy@inrae.fr, anne.tireau@inrae.fr, pascal.neveu@inrae.fr
******************************************************************************
'''
import opensilexClientToolsPython
import os
import logging
from functions import *
# Migration
# usage of a created instance of the API class
# ### V1.0
pythonClient = opensilexClientToolsPython.ApiClient()
pythonClient.connect_to_opensilex_ws(
identifier="admin@opensilex.org", password="admin", host="http://localhost:8666/rest")
logging.info("Headers and token : " + str(pythonClient.default_headers) + '\n')
# Functions
# Import variable from csv and googlesheet
# Googlesheet format example : https://docs.google.com/spreadsheets/d/1tjnKPQGp37Xd8d2SFMBQGR1NCzBO4iOSk05QjVgiHa8/edit?usp=sharing
# Googlesheet url exemple: https://docs.google.com/spreadsheets/d/1tjnKPQGp37Xd8d2SFMBQGR1NCzBO4iOSk05QjVgiHa8/edit#gid=0
spreadsheet_url = "https://docs.google.com/spreadsheets/d/1mqmXkSekWhdde7Ic4baiw9R3jSkS90CwTuQbZoaUIVk"
gid_number = "0"
migrate_variables_from_googlesheet(pythonClient, None, spreadsheet_url, gid_number, False)
exit()
# with specific header
# Header Key => "csv Name"
# configVariableHeaders = {
# "entityLabel": "entity.label",
# "entityUri": "entity.uri",
# "entityComment": "entity.comment",
# "characteristicLabel": "characteristic.label",
# "characteristicUri": "characteristic.uri",
# "characteristicComment": "characteristic.comment",
# "methodUri": "method.uri",
# "methodLabel": "method.label",
# "methodComment": "method.comment",
# "unitUri": "unit.uri",
# "unitLabel": "unit.label",
# "unitComment": "unit.comment",
# "traitUri": "trait.uri",
# "traitLabel": "trait.label",
# "variableUri": "uri",
# "variableLabel": "label",
# "variableComment": "comment",
# "dataType": "datatype",
# "alternativeLabel": "alternativeName"
# }
# Import variables from googlesheet
# You can defined row columns with the third argument configVariableHeaders
# Uncomment following lines to execute
# migrate_variables_from_googlesheet(pythonClient, None, spreadsheet_url, gid_number, False)
# Import variables from csv
# Uncomment following lines to execute
# csvVariablePath = os.path.join(os.path.abspath(os.path.dirname(__file__)),"csv_example","variables.csv")
# migrate_variables_from_csv(pythonClient, None, csvVariablePath, False)
# ############ # ############ # ############ # ############ # ############
# ############# ############ EXPERIMENTAL # ############ # ############
# ############ # ############ # ############ # ############ # ############
# create an experiment
expeTocreate = {
"uri": "http://www.opensilex.org/demo/Formation-2021",
"name": "Formation2021",
"objective": "For teaching purpose",
"start_date": "2021-04-27",
"end_date": "2021-04-27",
"species": ["http://aims.fao.org/aos/agrovoc/c_12332"],
"technical_supervisors": [],
"scientific_supervisors": [],
"projects": [],
"is_public": True,
"description": "Training OpenSILEX",
"groups": []
}
# uri = create_experiment(pythonClient,expeTocreate)
# Uncomment to execute
# uri = create_experiment(pythonClient, expe)
provenancesToSend = [{
"name": "ENVIRONMENTAL PROVENANCE DEMO - TRAINING",
"description": "Collected by several sensors",
"prov_agent": [
{
"uri": "http://www.opensilex.org/demo/set/devices/station-demo-sensor",
"rdf_type": "vocabulary:SensingDevice",
"settings": {}
}
]
}, {
'uri': "http://www.opensilex.org/demo/id/provenance/phenotyping-provenance-demo",
"name": "PHENOTYPING PROVENANCE DEMO - TRAINING",
"description": "Collected by an operator",
}]
# Uncomment to execute
create_provenances(pythonClient,provenancesToSend )
sensor = {"uri": "http://www.opensilex.org/demo/set/devices/station-demo-sensor", "name": "Demo sensor", "type": "vocabulary:Station",
"serial_number": "8173803780", "description": "Weather station"}
# Uncomment to execute
# create_sensor(pythonClient,sensor)
# http: // www.opensilex.org/demo/DIA2017-1
# csvFileName = "/home/charlero/savedisk/Projets/OpenSILEX/Presentation/Objets/objetsZA17.csv"
# In csv_example dir : "csv_example/objects.csv"
# Uncomment to execute
# csvObjectsPath = os.path.join(os.path.abspath(os.path.dirname(__file__)),"csv_example","data.csv")
# create_objects_from_csv(pythonClient, csvObjectsPath)
spreadsheet_url = "https://docs.google.com/spreadsheets/d/1tjnKPQGp37Xd8d2SFMBQGR1NCzBO4iOSk05QjVgiHa8"
gid_number = "1931021280"
# Uncomment to execute
#create_objects_from_googlesheet(pythonClient,spreadsheet_url,gid_number)
#update_objects_from_googlesheet(pythonClient,spreadsheet_url,gid_number)
# In csv_example dir : "csv_example/data.csv"
csvDataPath = os.path.join(os.path.abspath(os.path.dirname(__file__)),"csv_example","data.csv")
# Uncomment to execute
# add_data_from_csv(pythonClient, csvDataPath)
spreadsheet_url = "https://docs.google.com/spreadsheets/d/1tjnKPQGp37Xd8d2SFMBQGR1NCzBO4iOSk05QjVgiHa8"
gid_number = "2145718207"
# Uncomment to execute
add_data_from_googlesheet(pythonClient,spreadsheet_url,gid_number)