
function.server.logger.rq Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of corese-core Show documentation
Show all versions of corese-core Show documentation
Corese is a Semantic Web Factory (triple store and SPARQL endpoint) implementing RDF, RDFS, SPARQL 1.1
Query and Update.
The newest version!
#
# Functions for transformation st:logger
# Generate map and charts from connection history
# History recorded by server EventManager in ldscript static variable ?staticEventManagerMap
#
# use case: http://localhost:8080/srv/service/log
#
#
# generate a list of json description of IP address location
#
function us:jsonlist() {
letdyn (iplist = us:hostlist(),
ccount = 0, card = xt:size(iplist)) {
let (jsonlist = maplist(us:mydescribe, iplist)) {
return(jsonlist)
}
}
}
function us:mydescribe(ip) {
xt:print(set(ccount = ccount + 1), "/", card);
us:describe(ip)
}
#
# call service to get json description of IP address
#
function us:describe(ip) {
let (res = xt:read(concat("https://geo.ipify.org/api/v1?apiKey=at_XoGzTcrWBTSvdYhyQygXxP2NgBCNJ&ipAddress=", ip)),
json = xt:json(res)) {
xt:print(json, "\n") ;
return (us:compile(json))
}
}
# geo.ipify.org
# extract location from json description of IP address
#
function us:compile(json) {
let (pair = xt:get(json, "location"),
lat = xt:get(pair, "lat"),
lon = xt:get(pair, "lng"),
country = xt:get(pair, "country")
) {
xt:set(json, "lon", lon);
xt:set(json, "lat", lat);
xt:set(json, "country", country)
} ;
return (json)
}
#
# get host list from connection history
# history is recorded in ldscript static variable by server EventManager
# history is retrieved by function us:eventMap()
# function is written to be executed on localhost by /srv/service/log
# to query corese.inria.fr server history
#
function us:hostlist() {
let (select (aggregate(?key) as ?list)
where {
service {
#service {
select * where {
bind (us:eventMap() as ?map)
bind (xt:get(?map, st:hostlite) as ?host)
values (?key ?value) { unnest(?host) }
}
limit 999
}}) {
?list
}
}
#
# static variable set by server EventManager
#
@public
function us:eventMap() {
return (?staticEventManagerMap)
}
#
# list of location of IP address from my json
# use case: st:map in logger.rul
#
function us:location(jsonlist) {
maplist(us:locate, jsonlist)
}
#
# extract location from my json description of IP address
#
function us:locate(json) {
let (location = xt:get(json, "country"),
lat = xt:get(json, "lat"),
lon = xt:get(json, "lon")
) {
xt:list(location, xsd:decimal(lat), xsd:decimal(lon))
}
}
# 'https://api.ipgeolocation.io/ipgeo?apiKey=03b3bee276c244b596e42f6be03290e4&ip='
#
# jsonlist: list of json description of IP address
# generate a map(slotvalue->nb)
# use case: logger chart.rq
#
function us:nbmap(jsonlist, key) {
let (amap = xt:map()) {
for (json in jsonlist) {
let (cc = xt:get(json, key)) {
xt:set(amap, cc, coalesce(1 + xt:get(amap, cc), 1))
}
} ;
#xt:set(amap, "total", xt:size(jsonlist)) ;
return (amap)
}
}
function us:map() {
let (amap = xt:map()) {
map(lambda(ip, amap) { xt:set(amap, ip, 1) },
xt:list(
# IP address list
), xt:list(amap) );
return (amap)
}
}
function us:json(json, key) {
let (astr = strafter(json, concat("\"", key, "\": \"")),
pair = strbefore(astr, "\"")) {
return(pair)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy