Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit 51880576 authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

limit vehicle payload to vehicle's max payload

parent 0b2804d1
No related branches found
No related tags found
No related merge requests found
......@@ -29,72 +29,72 @@
* Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology
*/
using System;
using System.Data;
using System.Linq;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.Declaration
{
public sealed class Payloads : LookupData<Kilogram, Payloads.PayloadEntry>
{
protected override string ResourceId
{
get { return DeclarationData.DeclarationDataResourcePrefix + ".Payloads.csv"; }
}
protected override string ErrorMessage
{
get { throw new InvalidOperationException("ErrorMessage not applicable."); }
}
public Kilogram Lookup10Percent(Kilogram grossVehicleWeight)
{
var section = Data.GetSection(d => d.Key > grossVehicleWeight);
return VectoMath.Interpolate(section.Item1.Key, section.Item2.Key,
section.Item1.Value.Payload10Percent, section.Item2.Value.Payload10Percent,
grossVehicleWeight);
}
public Kilogram Lookup50Percent(Kilogram grossVehicleWeight)
{
var section = Data.GetSection(d => d.Key > grossVehicleWeight);
return VectoMath.Interpolate(section.Item1.Key, section.Item2.Key,
section.Item1.Value.Payload50Percent, section.Item2.Value.Payload50Percent,
grossVehicleWeight);
}
public Kilogram Lookup75Percent(Kilogram grossVehicleWeight)
{
var section = Data.GetSection(d => d.Key > grossVehicleWeight);
return VectoMath.Interpolate(section.Item1.Key, section.Item2.Key,
section.Item1.Value.Payload75Percent, section.Item2.Value.Payload75Percent,
grossVehicleWeight);
}
public Kilogram LookupTrailer(Kilogram grossVehicleWeight, Kilogram curbWeight)
{
return 0.75 * (grossVehicleWeight - curbWeight);
}
protected override void ParseData(DataTable table)
{
Data = table.Rows.Cast<DataRow>()
.ToDictionary(
kv => kv.ParseDouble("grossvehicleweight").SI<Kilogram>(),
kv => new PayloadEntry {
Payload10Percent = kv.ParseDouble("payload10%").SI<Kilogram>(),
Payload50Percent = kv.ParseDouble("payload50%").SI<Kilogram>(),
Payload75Percent = kv.ParseDouble("payload75%").SI<Kilogram>()
});
}
public sealed class PayloadEntry
{
public Kilogram Payload10Percent;
public Kilogram Payload50Percent;
public Kilogram Payload75Percent;
}
}
using System;
using System.Data;
using System.Linq;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.Declaration
{
public sealed class Payloads : LookupData<Kilogram, Payloads.PayloadEntry>
{
protected override string ResourceId
{
get { return DeclarationData.DeclarationDataResourcePrefix + ".Payloads.csv"; }
}
protected override string ErrorMessage
{
get { throw new InvalidOperationException("ErrorMessage not applicable."); }
}
public Kilogram Lookup10Percent(Kilogram grossVehicleWeight)
{
var section = Data.GetSection(d => d.Key > grossVehicleWeight);
return VectoMath.Interpolate(section.Item1.Key, section.Item2.Key,
section.Item1.Value.Payload10Percent, section.Item2.Value.Payload10Percent,
grossVehicleWeight);
}
public Kilogram Lookup50Percent(Kilogram grossVehicleWeight)
{
var section = Data.GetSection(d => d.Key > grossVehicleWeight);
return VectoMath.Interpolate(section.Item1.Key, section.Item2.Key,
section.Item1.Value.Payload50Percent, section.Item2.Value.Payload50Percent,
grossVehicleWeight);
}
public Kilogram Lookup75Percent(Kilogram grossVehicleWeight)
{
var section = Data.GetSection(d => d.Key > grossVehicleWeight);
return VectoMath.Interpolate(section.Item1.Key, section.Item2.Key,
section.Item1.Value.Payload75Percent, section.Item2.Value.Payload75Percent,
grossVehicleWeight);
}
public Kilogram LookupTrailer(Kilogram grossVehicleWeight, Kilogram curbWeight)
{
return 0.75 * (grossVehicleWeight - curbWeight);
}
protected override void ParseData(DataTable table)
{
Data = table.Rows.Cast<DataRow>()
.ToDictionary(
kv => kv.ParseDouble("grossvehicleweight").SI<Kilogram>(),
kv => new PayloadEntry {
Payload10Percent = kv.ParseDouble("payload10%").SI<Kilogram>(),
Payload50Percent = kv.ParseDouble("payload50%").SI<Kilogram>(),
Payload75Percent = kv.ParseDouble("payload75%").SI<Kilogram>()
});
}
public sealed class PayloadEntry
{
public Kilogram Payload10Percent;
public Kilogram Payload50Percent;
public Kilogram Payload75Percent;
}
}
}
\ No newline at end of file
......@@ -210,12 +210,13 @@ namespace TUGraz.VectoCore.Models.Declaration
trailers.Sum(t => t.TrailerCurbWeight).DefaultIfNull(0);
var payloads = row.Field<string>(missionType.ToString()).Split('/');
var vehicleWeight = curbWeight + body.CurbWeight;
Kilogram refLoad, lowLoad = 0.SI<Kilogram>();
if (payloads.Length == 2) {
lowLoad = GetLoading(payloads[0], grossVehicleWeight, trailers, true);
refLoad = GetLoading(payloads[1], grossVehicleWeight, trailers, false);
lowLoad = GetLoading(payloads[0], grossVehicleWeight, vehicleWeight, trailers, true);
refLoad = GetLoading(payloads[1], grossVehicleWeight, vehicleWeight, trailers, false);
} else {
refLoad = GetLoading(row.Field<string>(missionType.ToString()), grossVehicleWeight, trailers, false);
refLoad = GetLoading(row.Field<string>(missionType.ToString()), grossVehicleWeight, vehicleWeight, trailers, false);
}
refLoad = refLoad.LimitTo(0.SI<Kilogram>(), maxLoad);
......@@ -242,15 +243,17 @@ namespace TUGraz.VectoCore.Models.Declaration
return missions.ToArray();
}
private static Kilogram GetLoading(string payloadStr, Kilogram grossVehicleWeight,
private static Kilogram GetLoading(string payloadStr, Kilogram grossVehicleWeight, Kilogram vehicleWeight,
IEnumerable<MissionTrailer> trailers, bool lowLoading)
{
var refLoadValue = payloadStr.ToDouble(double.NaN);
if (double.IsNaN(refLoadValue)) {
return DeclarationData.GetPayloadForGrossVehicleWeight(grossVehicleWeight, payloadStr) +
trailers.Sum(
t => DeclarationData.GetPayloadForTrailerWeight(t.TrailerGrossVehicleWeight, t.TrailerCurbWeight, lowLoading))
.DefaultIfNull(0);
var vehiclePayload = DeclarationData.GetPayloadForGrossVehicleWeight(grossVehicleWeight, payloadStr)
.LimitTo(0.SI<Kilogram>(), grossVehicleWeight - vehicleWeight);
var trailerPayload = trailers.Sum(
t => DeclarationData.GetPayloadForTrailerWeight(t.TrailerGrossVehicleWeight, t.TrailerCurbWeight, lowLoading))
.DefaultIfNull(0);
return vehiclePayload + trailerPayload;
}
return refLoadValue.SI<Kilogram>();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment