sigo2copri content cache

This commit is contained in:
Rainer Gümpelein 2022-04-05 12:29:58 +02:00
parent d06556bd60
commit c40f326d37
8 changed files with 88 additions and 26 deletions

View file

@ -121,7 +121,7 @@ sub loop_sharees {
warn $@;
}
}else{
$bw->log("NO json ","","");
$bw->log("NO json from Operator:",$value->{operatorApp},"");
}
$bw->log("--> LOOP-end jsonclient loop_sharees user_group:\n",\@user_group,"");
}

View file

@ -642,7 +642,8 @@ elsif($q->param('request') eq "stations_available"){
my ($auth,$authraw) = $apif->auth_verify($q);
$response = { %$response, %$auth };
if($varenv{syshost} eq "shareeapp-sx"){
$response->{stations} = $si->sigo_available($q,\%varenv,$authraw);
($response->{stations},my $return2copri->{stations}) = $si->sigo_available($q,\%varenv,$authraw);
$tk->sigostation_cupdate($return2copri->{stations});
}else{
($response->{stations}, my $response_raw) = $apif->stations_available($q,\%varenv,$authraw);
}

View file

@ -114,6 +114,19 @@ sub sigo_available {
}
$response_out->{$station}->{operator_data} = {};
#just like caching
$return2copri->{$station}->{barcode} = $1 if($response_out->{$station}->{station} =~ /(\d+)/);#new on station context
$return2copri->{$station}->{int04} = $1 if($response_out->{$station}->{station} =~ /(\d+)/);
$return2copri->{$station}->{int06} = $1 if($response_out->{$station}->{gps_radius} =~ /(\d+)/);
$return2copri->{$station}->{txt01} = "$response_out->{$station}->{description}";
$return2copri->{$station}->{txt06} = "$response_out->{$station}->{gps}->{latitude},$response_out->{$station}->{gps}->{longitude}";
$return2copri->{$station}->{txt24} = "300102";
while (my ($key, $value) = each %{ $dbt->{copri_conf}->{station_state} }) {
if($response_out->{$station}->{state} eq $value){
$return2copri->{$station}->{int10} = $key;
}
}
}
}#end stations_available
@ -121,7 +134,7 @@ sub sigo_available {
#bike (mainly using sigojson state object)
my $bike = "SX$resp->{mobile_bike_id}";
if($bike && looks_like_number($resp->{mobile_bike_id}) && $resp->{status} eq "ACTIVE"){
if($bike && looks_like_number($resp->{mobile_bike_id}) && $resp->{status} eq "ACTIVE" && looks_like_number($resp->{site}->{id})){
print FILE "Bike: $bike\n";
$response_out->{$bike}->{bike} = "$bike";
$response_out->{$bike}->{authed} = "$authed";
@ -143,8 +156,8 @@ sub sigo_available {
}
#$response_out->{$bike}->{lock_state} = "undefined";#?
#$response_out->{$bike}->{lock_state} = "unlocked";# I think default should be unlocked
$response_out->{$bike}->{lock_state} = "locked";
#$response_out->{$bike}->{lock_state} = "locked";# I think default should be unlocked
$response_out->{$bike}->{lock_state} = "unlocked";
if($resp->{state}->{locked}){
$response_out->{$bike}->{lock_state} = "locked";
}
@ -164,6 +177,23 @@ sub sigo_available {
$response_out->{$bike}->{tariff_description}->{operator_agb} = "Mit der Mietrad Anmietung wird folgender Betreiber <a href='$dbt->{operator}->{$varenv->{dbname}}->{operatorApp}/site/agb.html' target='_blank'>AGB</a> zugestimmt (Demo)." if($auth->{c_id} && ($auth->{c_id} == 1842 || $auth->{c_id} == 5781 || $auth->{c_id} == 22262));
}
}
#just like caching
$return2copri->{$bike}->{int11} = 3;
$return2copri->{$bike}->{barcode} = $1 if($response_out->{$bike}->{bike} =~ /(\d+)/);
$return2copri->{$bike}->{int04} = $1 if($response_out->{$bike}->{station} =~ /(\d+)/);
$return2copri->{$bike}->{txt01} = "$response_out->{$bike}->{description}";
$return2copri->{$bike}->{txt06} = "$response_out->{$bike}->{gps}->{latitude},$response_out->{$bike}->{gps}->{longitude}";
$return2copri->{$bike}->{int19} = $1 if($response_out->{$bike}->{bike_charge} =~ /(\d+)/);
while (my ($key, $value) = each %{ $dbt->{copri_conf}->{bike_state} }) {
if($response_out->{$bike}->{state} eq $value){
$return2copri->{$bike}->{int10} = $key;
}
}
while (my ($key, $value) = each %{ $dbt->{copri_conf}->{lock_state} }) {
if($response_out->{$bike}->{lock_state} eq $value){
$return2copri->{$bike}->{int20} = $key;
}
}
}
}#end bikes_available

View file

@ -735,17 +735,14 @@ sub handler {
my $base_uri = "true";
my $title = "";
$title .= "devel $varenv{syshost} " if($dbt->{copri_conf}->{stage} eq "test");
#$title .= $dbt->{primary}->{$varenv{dbname}}->{title} if($dbt->{primary}->{$varenv{dbname}}->{title});
$title .= " " . $dbt->{operator}->{$varenv{dbname}}->{title} if($dbt->{operator}->{$varenv{dbname}}->{title});
$title .= " " . $dbt->{website}->{$varenv{syshost}}->{title} if($dbt->{website}->{$varenv{syshost}}->{title});
$title .= "devel " if($dbt->{copri_conf}->{stage} eq "test");
$title .= $dbt->{primary}->{$varenv{dbname}}->{title} if($dbt->{primary}->{$varenv{dbname}}->{title});
$title .= $dbt->{operator}->{$varenv{dbname}}->{title} if($dbt->{operator}->{$varenv{dbname}}->{title});
$title .= $dbt->{website}->{$varenv{syshost}}->{title} if($dbt->{website}->{$varenv{syshost}}->{title});
my $html5 = $q->start_html(-title=>"$title",
-lang=>'de',
-onload=>"$onload",
-oncontextmenu=>"$oncontextmenu",
#-id=>"page-top",
#'-data-spy'=>"scroll",
#'-data-target'=>".navbar-fixed-top",
-encoding=>"$html_charset",
-base=>"$base_uri",
-target=>"",

View file

@ -240,6 +240,7 @@ sub month_line(){
my $month_days = Days_in_Month($year,$mon);
my $factor = 100 / $month_days;
$factor = sprintf('%.3f',$factor);
my @month = calendar($mon, $year);
my $raster_mmpx = $factor . "%"; #bsp.: 100% / 31days

View file

@ -1034,7 +1034,7 @@ sub send_password(){
}
#TODO, not ready!
#sigobike just like caching and not realy used by app
sub sigobike_cupdate {
my $self = shift;
my $record_sigo = shift;
@ -1051,12 +1051,44 @@ sub sigobike_cupdate {
owner => "169",
};
$bw->log("UPDATE content from record_sigo with bike nr:",$record_sigo->{$bid}->{barcode},"");
#$rows = $self->update_record($dbh,$update,$record_sigo->{$bid}->{barcode});
$bw->log("UPDATE content from record_sigo with bike nr:",$update,"");
$rows = $dbt->update_record($dbh,$update,$record_sigo->{$bid});
if($rows != 1){
my $c_id = "";
$bw->log("INSERT content from record_sigo with bike nr:",$record_sigo->{$bid}->{barcode},"");
#$c_id = $self->insert_contentoid($dbh,$update,"");
$update->{itime} = "now()";
$bw->log("INSERT content from record_sigo with bike nr:",$update,"");
$c_id = $dbt->insert_contentoid($dbh,$update,"");
$rows = 1 if($c_id);
}
}
return $rows;
}
#sigostation just like caching and not realy used by app
sub sigostation_cupdate {
my $self = shift;
my $record_sigo = shift;
my $dbh = "";
my $rows = 0;
foreach my $sid (keys (%$record_sigo)){
my $update = {
%{$record_sigo->{$sid}},
table => "content",
template_id => "225",
main_id => "300016",
mtime => "now()",
owner => "169",
};
$bw->log("UPDATE content from record_sigo with bike nr:",$update,"");
$rows = $dbt->update_record($dbh,$update,$record_sigo->{$sid});
if($rows != 1){
my $c_id = "";
$update->{itime} = "now()";
$bw->log("INSERT content from record_sigo with bike nr:",$update,"");
$c_id = $dbt->insert_contentoid($dbh,$update,"");
$rows = 1 if($c_id);
}
}

View file

@ -92,8 +92,6 @@ my %varenv = $cf->envonline();
{-language=>'JAVASCRIPT',
-src=>"$varenv{metahost}/$dbt->{copri_conf}->{jsscript}"},
{-language=>'JAVASCRIPT',
-src=>"$varenv{metahost}/js/shareespecial.js"},
{-language=>'JAVASCRIPT',
-code=>"$dyn_js"}
],
-STYLE=>{
@ -153,18 +151,20 @@ print $q->div({-style=>'margin:15px;'},$q->a({-target=>'_blank', -href=>"$user_m
print $q->div({-style=>'margin:15px;'},"&nbsp;"),"\n";
#config
my $uriop = "$dbt->{operator}->{$operator_key}->{operatorApp}/APIjsonserver";
my $bike = "FR1006";
my $bike = "FR1003";
my $latitude = "47.927738";
my $longitude = "7.973855";
my $system = "Ilockit";
#not used
my $and_station_state_locking = "";
my $and_station_state_locked = "";
my $and_station_state_unlocked = "";
#sigo test lock
if(1==1){
$bike = "FR1006";
$system = "sigo";
#system=sigo
if($operator_key eq "sharee_sx"){
$bike = "SX1150";
$latitude = "";
$longitude = "";
#$and_station_state_locking = "&station_state=locking";
#$and_station_state_locked = "&station_state=locked";
#$and_station_state_unlocked = "&station_state=unlocked";

View file

@ -49,7 +49,8 @@ sub tpl(){
my $coo = $q->cookie('domcookie') || $q->param('sessionid') || "";
#my $api_test = "sharee_kn";
#my $api_test = "sharee_fr01";
my $api_test = "sharee_wue";
#my $api_test = "sharee_wue";
my $api_test = "sharee_sx";
print $q->div({-style=>'float:right;text-align:right;height:25px;padding:6px 15px;background-color:white'},$q->a({-style=>"background-color:#ffffff;color:#$bgcolor1;", -href=>"$varenv->{metahost}/src/scripts/tests/index.pl?sessionid=$coo\&api_test=$api_test", -target=>'_blank'}," [ tests --> $api_test ] ")),"\n";
}