-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.py
175 lines (154 loc) · 5.57 KB
/
web.py
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
from datetime import datetime
from flask import request, jsonify
from timeline import *
from improvement import *
from skill_allocation import *
from prefixes import prefixes
@app.route('/timeline/')
def get_skill_timeline():
"""Selects all employees with the given skill that are active at the company."""
today = datetime.today().date()
skillURI = str("http://data.europa.eu/esco/skill/" + request.args.get("skillid"))
q = prefixes + """
SELECT distinct ?name ?sDate ?aDate ?eDate
WHERE{
GRAPH <http://mu.semte.ch/application>{
?employee default:hasSkill ?skillemp.
?employee foaf:name ?name.
?skillemp esco:hasSkill <%s>.
?employee default:function ?function.
?function default:startDate ?sDate.
?skillemp default:acquired ?aDate.
OPTIONAL{
?function default:endDate ?date.
} BIND(IF(BOUND(?date), ?date, %s ) AS ?eDate)
}
}""" % (skillURI, sparql_escape(today))
data = helpers.query(q)
bindings = data["results"]["bindings"]
tl = Timeline()
for b in bindings:
e = TimelineElement(b["aDate"]["value"], b["sDate"]["value"], b["eDate"]["value"])
tl.add_element(e)
if tl.has_elements():
return jsonify(tl.createTimeLine())
else:
return jsonify({'data': []})
@app.route('/skills/')
def all_skills():
q = prefixes + """
SELECT distinct (?skill as ?skillURI) (str(?literal) as ?skillName) ?id
WHERE{
GRAPH <http://mu.semte.ch/application>{
?skill a esco:Skill.
?skill ^esco:hasSkill ?se.
?se a default:EmployeeSkill.
?skill skos:prefLabel ?literal.
?skill <http://mu.semte.ch/vocabularies/core/uuid> ?id.
}
}"""
res = helpers.query(q)
data = res["results"]["bindings"]
jobj = {"data":[]}
for e in data:
jobj["data"].append({
"attributes": {
"name": e["skillName"]["value"]
},
"id": e["id"]["value"],
"type": "skills"
})
return jsonify(jobj)
@app.route('/bubble/')
def local_bubble():
date = request.args.get("date")
date = datetime.strptime(date, "%Y-%m-%d").date()
q = prefixes + """
SELECT (str(?skillName) as ?skillName) ?skillID (count(?skillemp) as ?count)
WHERE{
?employee default:function ?function.
?function esco:hasOccupation ?occ.
?occ skos:prefLabel ?occN.
?employee default:hasSkill ?skillemp.
?skillemp esco:hasSkill ?skill.
?skill mu:uuid ?skillID.
?skill skos:prefLabel ?skillName.
?skillemp default:acquired ?aDate.
?function default:startDate ?sDate.
FILTER(?aDate < %s)
FILTER(%s > ?sDate)
} group by ?skillName ?skillID
""" % (sparql_escape(date), sparql_escape(date))
res = helpers.query(q)
data = res["results"]["bindings"]
jobj = {"data": []}
for e in data:
jobj["data"].append({
"attributes": {
"name": e["skillName"]["value"],
"count": e["count"]["value"]
},
"id": e["skillID"]["value"],
"type": "counts"
})
return jsonify(jobj)
@app.route('/occupations/')
def get_all_occupations():
q = prefixes + """
SELECT distinct (?occ as ?occURI) (str(?literal) as ?occName) ?id
WHERE{
GRAPH <http://mu.semte.ch/application>{
?so a default:EmployeeFunction.
?so esco:hasOccupation ?occ.
?occ skos:prefLabel ?literal.
?occ <http://mu.semte.ch/vocabularies/core/uuid> ?id.
}
}"""
res = helpers.query(q)
data = res["results"]["bindings"]
jobj = {"data": []}
for e in data:
jobj["data"].append({
"attributes": {
"name": e["occName"]["value"]
},
"id": e["id"]["value"],
"type": "occupations"
})
return jsonify(jobj)
@app.route('/improvements/')
def get_inprovement():
today = datetime.today().date()
q = prefixes + """
SELECT distinct ?skillName ?skillID ?empName ?empID ?occ ?sDate ?aDate ?eDate (str(?occN) as ?occupation)
WHERE{
?employee default:hasSkill ?skillemp.
?employee mu:uuid ?empID.
?employee foaf:name ?empName.
?employee default:function ?function.
?function esco:hasOccupation ?occ.
?occ skos:prefLabel ?occN.
?skillemp esco:hasSkill ?skill.
?skill mu:uuid ?skillID.
?skill skos:prefLabel ?skillName.
?skillemp default:acquired ?aDate.
?employee default:function ?function.
?function default:startDate ?sDate.
OPTIONAL{
?function default:endDate ?date.
} BIND(IF(BOUND(?date), ?date, %s ) AS ?eDate)
}
""" % (sparql_escape(today))
data = helpers.query(q)
bindings = data["results"]["bindings"]
for b in bindings:
acquired = b["aDate"]["value"]
start = b["sDate"]["value"]
end = b["eDate"]["value"]
if start <= acquired <= end:
EmployeeImprovements(b["empID"]["value"], b["empName"]["value"], b["occupation"]["value"])
SkillImprovements(b["skillID"]["value"], b["skillName"]["value"])
if Improvement.has_elements():
return jsonify({'data': Improvement.get_all_improvements()})
else:
return jsonify({'data': []})