Commit 9452935b authored by Christine Plumejeaud's avatar Christine Plumejeaud
Browse files

Change the API for travels in order to send back travels according a ship_id or a captain_id.

Fixed a bug on trim of name to have the various truely distinct names of ships or captain.
Added new comments on tables of the API.
parent 22949053
......@@ -353,12 +353,16 @@ def getTravels():
- params : **all** | tableau des noms longs des attributs de l'API à renvoyer
params=pointcall,pointcall_uhgs_id for instance
- both_to : true | **false**
- date = 1787 for instance
- ship_id : identifier of the ship
- captain_id : identifier of the captain
http://127.0.0.1:5004/api/travels/?format=csv&both_to=false
http://127.0.0.1:80/api/travels/?format=csv&both_to=true&shortenfields=true&date=1789
http://127.0.0.1:80/api/travels/?format=json&params=id,departure,destination,destination_uhgs_id
http://127.0.0.1:80/api/travels/?format=json&params=id,departure,destination,destination_uhgs_id&shortenfields=true
http://127.0.0.1:80/api/travels/?format=json&params=travel_rank,departure,destination,ship_name,captain_name,geom,pointpath&ship_id=0004171N
"""
import pandas as pd
#filename = os.path.join(APP_DATA, 'travels_API_11mai2020.csv')
......@@ -399,6 +403,24 @@ def getTravels():
query = query + """ where (substring(departure_out_date for 4) = '%s' or substring(destination_in_date for 4) = '%s') """ % (date, date)
print(query)
## filter following a ship_id
ship_id = request.args.get("ship_id")
if (ship_id is not None and len(ship_id)==8) :
if 'where' in query :
query = query + """ and (ship_id = '%s' )""" % (ship_id)
else :
query = query + """ where (ship_id = '%s' ) """ % (ship_id)
print(query)
## filter following a captain_id
captain_id = request.args.get("captain_id")
if (captain_id is not None and len(captain_id)==8) :
if 'where' in query :
query = query + """ and (captain_id = '%s' )""" % (captain_id)
else :
query = query + """ where (captain_id = '%s' ) """ % (captain_id)
print(query)
return retrieveDataAndFormatOutput(query, api='travels')
@app.route('/api/rawflows/')
......
......@@ -157,6 +157,17 @@ but with a filter by default, to avoid duplicates :
- date : par défaut, pas de filtre sur les dates
- ship_id : par défaut, pas de filtre sur les identifiants de navire.
Exemple :
`ship_id=0004171N`
- captain_id : par défaut, pas de filtre sur les identifiants de capitaines.
Exemple :
`captain_id=00011085`
## /rawflows?
......
......@@ -38,10 +38,10 @@ FROM
(select captain_local_id, array_to_json(array_agg(json_build_object(captain_name ,occurences))) as occurences_name
FROM
(
Select captain_id as captain_local_id, captain_name, count (distinct source_doc_id) as occurences
Select captain_id as captain_local_id, trim(captain_name) as captain_name, count (distinct source_doc_id) as occurences
FROM navigoviz.pointcall p
WHERE p.captain_id in (select distinct captain_id from built_travels)
GROUP BY captain_name, captain_id
GROUP BY trim(captain_name) , captain_id
ORDER BY captain_id, occurences DESC
) t
WHERE occurences > 0
......@@ -50,6 +50,24 @@ GROUP BY captain_local_id
WHERE c.captain_id = k.captain_local_id;
-- 12329
-- bug signalé le 29 juin par Bernard
-- Par exemple (pour le captain_id 00011085),
-- je suis tombé sur des variantes de noms de capitaines (occurences_names) qui ne sont pas vraiment toutes différentes :
select * from navigoviz.captain where captain_id = '00011085';
select * from navigoviz.pointcall where captain_id = '00011085';
select * from navigoviz.built_travels where captain_id = '00011085';
-- [{"Bordes, Jean" : 4},{"Border, Jean" : 1},{"Bordery, Jean" : 1},{"Bordery, Jean " : 1},{"Bordes, Jean " : 1}]
Select captain_id as captain_local_id, trim(captain_name) as captain_name, count (distinct source_doc_id) as occurences
FROM navigoviz.pointcall p
WHERE p.captain_id in (select distinct captain_id from built_travels) and captain_id = '00011085'
GROUP BY trim(captain_name) , captain_id
ORDER BY captain_id, occurences desc
-- ok, trim règle le pb
-- select * from navigoviz.captain where occurences_names is null;
update navigoviz.captain c set occurences_birthplaces = k.occurence_birthplace
......@@ -130,15 +148,15 @@ update navigoviz.ship s set occurences_names = k.occurences_name
FROM
(select ship_id, array_to_json(array_agg(json_build_object(ship_name ,occurences))) as occurences_name
from (
Select ship_id, ship_name, count (distinct source_doc_id) as occurences
Select ship_id, trim(ship_name) as ship_name, count (distinct source_doc_id) as occurences
FROM navigoviz.pointcall p
WHERE p.ship_id in (select distinct ship_id from built_travels)
GROUP BY ship_name,ship_id
GROUP BY trim(ship_name),ship_id
ORDER BY ship_id, occurences DESC
) as k
GROUP BY ship_id
) as k
WHERE s.ship_id = k.ship_id;
WHERE s.ship_id = k.ship_id; -- 11618
select * from navigoviz.built_travels where ship_name is null ;
......@@ -302,8 +320,10 @@ select travel_id as step_id, source_text, outdate_fixed, indate_fixed, departure
ship_id, ship_name, tonnage_class, ship_flag_standardized_fr, homeport_toponyme_fr,
captain_id , captain_name, birthplace, citizenship, travel_rank
from navigoviz.built_travels
where ship_id = '0004171N' and source_entry!='both-to'
order by travel_rank;
where ship_id in ( '0007498N', '0002931N', '0004155N', '0021517N', '0003951N', '0004171N', '0002537N', '0002350N', '0014650N', '0000011N', '0012406N', '0002344N', '0014815N', '0000063N', '0000447N', '0004355N', '0015074N', '0000068N', '0000144N','0000684N', '0002454N', '0000039N', '0000131N', '0012925N', '0000305N', '0000125N', '0007004N', '0021517N')
--= '0004171N'
and source_entry!='both-to'
order by ship_id, travel_rank;
comment on table navigoviz.ship is 'List of ships''descriptions with variantes for the name, flag, homeport, tonnage_class and class of ship';
comment on table navigoviz.captain is 'List of captains''descriptions with variantes for the name, citizenship, birthplace of captain';
......@@ -462,4 +482,93 @@ from (select ughs_id, array_agg(ughs_id_sup) as list_sup_uhgs_id
update navigoviz.pointcall p set list_inf_uhgs_id = k.list_inf_uhgs_id
from (select ughs_id_sup, array_agg(ughs_id) as list_inf_uhgs_id
from ports.generiques_inclusions_geo_csv gigc
group by ughs_id_sup) as k where k.ughs_id_sup = p.pointcall_uhgs_id;
\ No newline at end of file
group by ughs_id_sup) as k where k.ughs_id_sup = p.pointcall_uhgs_id;
select travel_id as step_id, source_text, outdate_fixed, indate_fixed, departure_uhgs_id, departure_fr, destination_uhgs_id, destination_fr,
ship_id, ship_name, tonnage_class, ship_flag_standardized_fr, homeport_toponyme_fr,
captain_id , captain_name, birthplace, citizenship, travel_rank
from navigoviz.built_travels
where ship_id in ('0004171N', '0004155N', '0002931N')
-- ship_id in ( '0007498N', '0002931N', '0004155N', '0021517N', '0003951N', '0004171N', '0002537N', '0002350N', '0014650N', '0000011N', '0012406N', '0002344N', '0014815N', '0000063N', '0000447N', '0004355N', '0015074N', '0000068N', '0000144N','0000684N', '0002454N', '0000039N', '0000131N', '0012925N', '0000305N', '0000125N', '0007004N', '0021517N')
--= '0004171N'
and source_entry!='both-to'
order by ship_id, travel_rank;
-- la bonne requete pour faire l'union des historiens et de l'algo
select row_number() over (PARTITION BY ship_id order by outdate_fixed asc, id asc, couleur desc) as travel_rank, * from (
select id, ship_id, source_depart as source_text, departure, destination, outdate_fixed, departure_uncertainity, destination_uncertainity, depart_net_route_marker, arrivee_net_route_marker, direct, couleur, st_makeline(pointpath) as geom
from public.travel_heloise_historien where ship_id in ('0004171N', '0004155N', '0002931N')
union
select id, ship_id, source_depart as source_text, departure, destination, outdate_fixed, departure_uncertainity, destination_uncertainity, depart_net_route_marker, arrivee_net_route_marker, direct, couleur, st_makeline(pointpath) as geom
from public.travel_heloise_algo where couleur = 'red' and ship_id in ('0004171N', '0004155N', '0002931N')
order by ship_id, outdate_fixed, id
) as k
create table navigoviz.built_travels_backup17juin22 as (select * from navigoviz.built_travels)
update navigoviz.pointcall p set pointcall_uncertainity = -2
from public.pointcall_checked c where p.pkid=c.pkid and certitude='Déclaré'
create table navigoviz.uncertainity_travels as (
select row_number() over (PARTITION BY ship_id order by outdate_fixed asc, id asc, destination_uncertainity asc) as travel_rank, *
from
(
select * from public.uncertainity_travels_historien
union
select * from public.uncertainity_travels_algo
where destination_uncertainity = -5 or departure_uncertainity = -5
order by ship_id, outdate_fixed, id
) as k
)
drop table navigoviz.routepaths
create table navigoviz.routepaths (
from_uhgs_id text,
from_toponyme_fr text,
to_uhgs_id text,
to_toponyme_fr text,
m_offset double precision,
p_distance_ratio integer,
pointpath geometry[],
elapseTime float,
nbPoints int
);
truncate navigoviz.routepaths;
select count(*) from navigoviz.uncertainity_travels --228
select depart_pointcall_uhgs_id, departure, arrivee_pointcall_uhgs_id, destination, pointpath , array_length(pointpath, 1)
from navigoviz.uncertainity_travels where pointpath is not null --45
insert into navigoviz.routepaths (from_uhgs_id, from_toponyme_fr, to_uhgs_id, to_toponyme_fr, m_offset, p_distance_ratio, pointpath, nbPoints)
select depart_pointcall_uhgs_id, departure, arrivee_pointcall_uhgs_id, destination, 10000, 50000, pointpath , array_length(pointpath, 1)
from navigoviz.uncertainity_travels where pointpath is not null;
/*
insert into navigoviz.routepaths (from_uhgs_id, from_toponyme_fr, to_uhgs_id, to_toponyme_fr, pointpath, nbPoints)
select arrivee_pointcall_uhgs_id, destination, depart_pointcall_uhgs_id, departure, pointpath , array_length(pointpath, 1)
from navigoviz.uncertainity_travels where pointpath is not null;
*/
ports.points_on_path(depart_pointcall_uhgs_id , arrivee_pointcall_uhgs_id, 10000, 50000)
update navigoviz.routepaths set
select t.*, r.pointpath
from navigoviz.routepaths r, navigoviz.uncertainity_travels t
where (from_uhgs_id = t.depart_pointcall_uhgs_id and to_uhgs_id = t.arrivee_pointcall_uhgs_id)
or (to_uhgs_id=t.depart_pointcall_uhgs_id and from_uhgs_id=t.arrivee_pointcall_uhgs_id)
update navigoviz.built_travels set pointpath = r.pointpath , geom = st_makeline(r.pointpath)
from navigoviz.routepaths r
where (from_uhgs_id = departure_uhgs_id and to_uhgs_id=destination_uhgs_id)
or (from_uhgs_id = destination_uhgs_id and to_uhgs_id=departure_uhgs_id)
and r.pointpath is not null
-- 5858
select * from navigoviz.built_travels
where pointpath is not null and ship_id = '0004155N'
order by travel_id
select distinct ship_id from navigoviz.built_travels where pointpath is not null
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment