Fixed eta / etd search error and evaluate searchFromEta as filter used against the back-end to retrieve shipcalls from the past

This commit is contained in:
Daniel Schick 2023-10-23 16:02:28 +02:00
parent a763589587
commit 13c5866884
5 changed files with 262 additions and 222 deletions

View File

@ -1,8 +1,8 @@
//----------------------
// <auto-generated>
// Generated REST API Client Code Generator v1.8.7.0 on 13.10.2023 10:51:41
// Using the tool OpenAPI Generator v7.0.1
// Generated REST API Client Code Generator v1.8.4.0 on 23.10.2023 09:06:40
// Using the tool OpenAPI Generator v7.0.0
// </auto-generated>
//----------------------
@ -139,9 +139,10 @@ namespace BreCalClient.misc.Api
/// Gets a list of ship calls
/// </summary>
/// <exception cref="BreCalClient.misc.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="pastDays">number of days in the past to include in the result. *Example: 7*. (optional)</param>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <returns>List&lt;Shipcall&gt;</returns>
List<Shipcall> ShipcallsGet(int operationIndex = 0);
List<Shipcall> ShipcallsGet(int? pastDays = default(int?), int operationIndex = 0);
/// <summary>
/// Gets a list of ship calls
/// </summary>
@ -149,9 +150,10 @@ namespace BreCalClient.misc.Api
///
/// </remarks>
/// <exception cref="BreCalClient.misc.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="pastDays">number of days in the past to include in the result. *Example: 7*. (optional)</param>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <returns>ApiResponse of List&lt;Shipcall&gt;</returns>
ApiResponse<List<Shipcall>> ShipcallsGetWithHttpInfo(int operationIndex = 0);
ApiResponse<List<Shipcall>> ShipcallsGetWithHttpInfo(int? pastDays = default(int?), int operationIndex = 0);
/// <summary>
/// Create a new ship call
/// </summary>
@ -413,10 +415,11 @@ namespace BreCalClient.misc.Api
///
/// </remarks>
/// <exception cref="BreCalClient.misc.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="pastDays">number of days in the past to include in the result. *Example: 7*. (optional)</param>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns>Task of List&lt;Shipcall&gt;</returns>
System.Threading.Tasks.Task<List<Shipcall>> ShipcallsGetAsync(int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
System.Threading.Tasks.Task<List<Shipcall>> ShipcallsGetAsync(int? pastDays = default(int?), int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
/// <summary>
/// Gets a list of ship calls
/// </summary>
@ -424,10 +427,11 @@ namespace BreCalClient.misc.Api
///
/// </remarks>
/// <exception cref="BreCalClient.misc.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="pastDays">number of days in the past to include in the result. *Example: 7*. (optional)</param>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns>Task of ApiResponse (List&lt;Shipcall&gt;)</returns>
System.Threading.Tasks.Task<ApiResponse<List<Shipcall>>> ShipcallsGetWithHttpInfoAsync(int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
System.Threading.Tasks.Task<ApiResponse<List<Shipcall>>> ShipcallsGetWithHttpInfoAsync(int? pastDays = default(int?), int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
/// <summary>
/// Create a new ship call
/// </summary>
@ -1217,20 +1221,22 @@ namespace BreCalClient.misc.Api
/// Gets a list of ship calls
/// </summary>
/// <exception cref="BreCalClient.misc.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="pastDays">number of days in the past to include in the result. *Example: 7*. (optional)</param>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <returns>List&lt;Shipcall&gt;</returns>
public List<Shipcall> ShipcallsGet(int operationIndex = 0)
public List<Shipcall> ShipcallsGet(int? pastDays = default(int?), int operationIndex = 0)
{
BreCalClient.misc.Client.ApiResponse<List<Shipcall>> localVarResponse = ShipcallsGetWithHttpInfo();
BreCalClient.misc.Client.ApiResponse<List<Shipcall>> localVarResponse = ShipcallsGetWithHttpInfo(pastDays);
return localVarResponse.Data;
}
/// <summary>
/// Gets a list of ship calls
/// </summary>
/// <exception cref="BreCalClient.misc.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="pastDays">number of days in the past to include in the result. *Example: 7*. (optional)</param>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <returns>ApiResponse of List&lt;Shipcall&gt;</returns>
public BreCalClient.misc.Client.ApiResponse<List<Shipcall>> ShipcallsGetWithHttpInfo(int operationIndex = 0)
public BreCalClient.misc.Client.ApiResponse<List<Shipcall>> ShipcallsGetWithHttpInfo(int? pastDays = default(int?), int operationIndex = 0)
{
BreCalClient.misc.Client.RequestOptions localVarRequestOptions = new BreCalClient.misc.Client.RequestOptions();
string[] _contentTypes = new string[] {
@ -1249,6 +1255,10 @@ namespace BreCalClient.misc.Api
{
localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept);
}
if (pastDays != null)
{
localVarRequestOptions.QueryParameters.Add(BreCalClient.misc.Client.ClientUtils.ParameterToMultiMap("", "past_days", pastDays));
}
localVarRequestOptions.Operation = "DefaultApi.ShipcallsGet";
localVarRequestOptions.OperationIndex = operationIndex;
// authentication (ApiKey) required
@ -1272,22 +1282,24 @@ namespace BreCalClient.misc.Api
/// Gets a list of ship calls
/// </summary>
/// <exception cref="BreCalClient.misc.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="pastDays">number of days in the past to include in the result. *Example: 7*. (optional)</param>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns>Task of List&lt;Shipcall&gt;</returns>
public async System.Threading.Tasks.Task<List<Shipcall>> ShipcallsGetAsync(int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
public async System.Threading.Tasks.Task<List<Shipcall>> ShipcallsGetAsync(int? pastDays = default(int?), int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
{
BreCalClient.misc.Client.ApiResponse<List<Shipcall>> localVarResponse = await ShipcallsGetWithHttpInfoAsync(operationIndex, cancellationToken).ConfigureAwait(false);
BreCalClient.misc.Client.ApiResponse<List<Shipcall>> localVarResponse = await ShipcallsGetWithHttpInfoAsync(pastDays, operationIndex, cancellationToken).ConfigureAwait(false);
return localVarResponse.Data;
}
/// <summary>
/// Gets a list of ship calls
/// </summary>
/// <exception cref="BreCalClient.misc.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="pastDays">number of days in the past to include in the result. *Example: 7*. (optional)</param>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns>Task of ApiResponse (List&lt;Shipcall&gt;)</returns>
public async System.Threading.Tasks.Task<BreCalClient.misc.Client.ApiResponse<List<Shipcall>>> ShipcallsGetWithHttpInfoAsync(int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
public async System.Threading.Tasks.Task<BreCalClient.misc.Client.ApiResponse<List<Shipcall>>> ShipcallsGetWithHttpInfoAsync(int? pastDays = default(int?), int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
{
BreCalClient.misc.Client.RequestOptions localVarRequestOptions = new BreCalClient.misc.Client.RequestOptions();
string[] _contentTypes = new string[] {
@ -1306,6 +1318,10 @@ namespace BreCalClient.misc.Api
{
localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept);
}
if (pastDays != null)
{
localVarRequestOptions.QueryParameters.Add(BreCalClient.misc.Client.ClientUtils.ParameterToMultiMap("", "past_days", pastDays));
}
localVarRequestOptions.Operation = "DefaultApi.ShipcallsGet";
localVarRequestOptions.OperationIndex = operationIndex;
// authentication (ApiKey) required

View File

@ -68,13 +68,13 @@ paths:
/shipcalls:
get:
summary: Gets a list of ship calls
#parameters:
# - name: participant_id
# in: query
# required: true
# description: "**Id of participant**. *Example: 2*. Id of participant entity requesting ship calls"
# schema:
# type: integer
parameters:
- name: past_days
in: query
required: false
description: "number of days in the past to include in the result. *Example: 7*."
schema:
type: integer
responses:
200:
description: ship call list

View File

@ -47,6 +47,8 @@ namespace BreCalClient
private bool? _showCanceled = null;
private SortOrder? _sortOrder;
private int searchPastDays = 0;
// private bool _filterChanged = false;
// private bool _sequenceChanged = false;
@ -293,7 +295,11 @@ namespace BreCalClient
List<Shipcall>? shipcalls = null;
try
{
if(this.searchPastDays != 0)
shipcalls = await _api.ShipcallsGetAsync(this.searchPastDays);
else
shipcalls = await _api.ShipcallsGetAsync();
this.Dispatcher.Invoke(new Action(() =>
{
labelGeneralStatus.Text = $"Connection {ConnectionStatus.SUCCESSFUL}";
@ -430,6 +436,21 @@ namespace BreCalClient
{
SearchFilterModel sfm = this.searchFilterControl.SearchFilter;
if( sfm.EtaFrom.HasValue && sfm.EtaFrom < DateTime.Now.AddDays(-2))
{
int daysInThePast = (int)Math.Ceiling((DateTime.Now - sfm.EtaFrom.Value).TotalDays);
if (this.searchPastDays != daysInThePast)
{
this.searchPastDays = daysInThePast;
_refreshImmediately = true; // set flag to avoid timer loop termination
_tokenSource.Cancel(); // force timer loop end
}
}
else
{
searchPastDays = 0;
}
this._visibleControlModels.Clear();
// first add everything
this._visibleControlModels.AddRange(_allShipcallsDict.Values);

View File

@ -17,6 +17,7 @@ def GetShipcalls():
token = request.headers.get('Authorization')
options = {}
options["participant_id"] = request.args.get("participant_id")
options["past_days"] = request.args.get("past_days", default=2, type=int)
return impl.shipcalls.GetShipcalls(options)
else:

View File

@ -19,10 +19,12 @@ def GetShipcalls(options):
pooledConnection = local_db.getPoolConnection()
commands = pydapper.using(pooledConnection)
data = commands.query("SELECT id, ship_id, type, eta, voyage, etd, arrival_berth_id, departure_berth_id, tug_required, pilot_required, " +
"flags, pier_side, bunkering, replenishing_terminal, replenishing_lock, draft, tidal_window_from, tidal_window_to, rain_sensitive_cargo, recommended_tugs, " +
"anchored, moored_lock, canceled, evaluation, evaluation_message, created, modified FROM shipcall WHERE eta IS NULL OR eta >= DATE(NOW() - INTERVAL 2 DAY) " +
"ORDER BY eta", model=model.Shipcall)
"anchored, moored_lock, canceled, evaluation, evaluation_message, created, modified FROM shipcall WHERE ((type = 1 OR type = 2) AND eta >= DATE(NOW() - INTERVAL %d DAY) " % (options["past_days"]) +
"OR (type = 3 AND etd >= DATE(NOW() - INTERVAL %d DAY)) " % (options["past_days"]) +
"ORDER BY eta" , model=model.Shipcall)
for shipcall in data:
participant_query = "SELECT participant_id, type FROM shipcall_participant_map WHERE shipcall_id=?shipcall_id?";
for record in commands.query(participant_query, model=dict, param={"shipcall_id" : shipcall.id}, buffered=False):