Skip to content

Changed average to median#41

Draft
juffe84 wants to merge 1 commit intomasterfrom
juhaMedian
Draft

Changed average to median#41
juffe84 wants to merge 1 commit intomasterfrom
juhaMedian

Conversation

@juffe84
Copy link
Collaborator

@juffe84 juffe84 commented Oct 20, 2024

No description provided.

Copy link
Owner

@japsuu japsuu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do NOT merge this to master. This commit has major issues, and does not work as intended.

Will do a proper writeup tomorrow.

Copy link
Owner

@japsuu japsuu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All pending tasks need to be completed before the PR can be merged to master

Comment on lines 4 to +5
using GNSSStatus.Utils;
using YamlDotNet.Serialization;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not leave unused using statements

Comment on lines +28 to +30
//public readonly List<string> RoverFixCache = new();
//public readonly List<string> RoverSatInUseCache = new();
//public readonly List<GGAData.FixType> FixTypesCache = new();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(RSPEC-125) Sections of code should not be commented out.
Commented-out code distracts the focus from the actual executed code. It creates a noise that increases maintenance code. And because it is never executed, it quickly becomes out of date and invalid.
Commented-out code should be deleted and can be retrieved from source control history if required.

double roverXAverage = RoverXCache.Count > 0 ? RoverXCache.Average() : 0;
double roverYAverage = RoverYCache.Count > 0 ? RoverYCache.Average() : 0;
double roverZAverage = RoverZCache.Count > 0 ? RoverZCache.Average() : 0;
*/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(RSPEC-125) Sections of code should not be commented out.

{
JsonPayloadBuilder builder = new();

/*
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(RSPEC-125) Sections of code should not be commented out.

double deltaYMedian = DeltaYCache[medianIndex];
double deltaXy = Math.Sqrt(deltaXMedian * deltaXMedian + deltaYMedian * deltaYMedian);
string roverUtCTime = RoverUtcTimeCache[medianIndex];
GGAData.FixType roverFixType = RoverFixTypeCache[medianIndex];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FixTypes are no longer based on the worst in measure interval.

Comment on lines +168 to +171
var indexedNumbers = list
.Select((value, index) => new { Value = value, Index = index })
.OrderBy(x => x.Value)
.ToArray();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allocates >3 IEnumerables, not ok in embedded systems

public (int, int) CalculateMedianIndex<T>(List<T> list)
{
// Luo kopio alkuperäisestä listasta ja liitä siihen alkuperäiset indeksit
var indexedNumbers = list
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer strong types where possible (maintainability)

Comment on lines +168 to +187
var indexedNumbers = list
.Select((value, index) => new { Value = value, Index = index })
.OrderBy(x => x.Value)
.ToArray();

int count = indexedNumbers.Length;

if (count % 2 == 0)
{
// Jos määrä on parillinen, laske kahden keskimmäisen luvun indeksit
int mid1Index = indexedNumbers[count / 2 - 1].Index;
int mid2Index = indexedNumbers[count / 2].Index;
return (mid1Index, mid2Index);
}
else
{
// Jos määrä on pariton, valitse keskimmäisen luvun indeksi
int medianIndex = indexedNumbers[count / 2].Index;
return (medianIndex, -1); // -1 tarkoittaa, että vain yksi mediaani löytyy
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not work as expected, and returns incorrect indices for generic types that do not implement IComparable.

Comment on lines +17 to +26
public readonly List<string> RoverUtcTimeCache = new();
public readonly List<GGAData.FixType> RoverFixTypeCache = new();
public readonly List<int> RoverSatInUseCache = new();
public readonly List<float> RoverPDopCache = new();
public readonly List<float> RoverVDopCache = new();
public readonly List<float> RoverHDopCache = new();
public readonly List<float> RoverErrorLatitudeCache = new();
public readonly List<float> RoverErrorLongitudeCache = new();
public readonly List<float> RoverErrorAltitudeCache = new();
public readonly List<double> RoverBaselineCache = new();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to prefix everything with "rover"

Comment on lines +11 to +26
public readonly List<double> DeltaZCache = new();
public readonly List<double> DeltaXCache = new();
public readonly List<double> DeltaYCache = new();
public readonly List<double> DeltaZCache = new();
public readonly List<double> RoverXCache = new();
public readonly List<double> RoverYCache = new();
public readonly List<double> RoverZCache = new();
public readonly List<GGAData.FixType> FixTypesCache = new();
public readonly List<string> RoverUtcTimeCache = new();
public readonly List<GGAData.FixType> RoverFixTypeCache = new();
public readonly List<int> RoverSatInUseCache = new();
public readonly List<float> RoverPDopCache = new();
public readonly List<float> RoverVDopCache = new();
public readonly List<float> RoverHDopCache = new();
public readonly List<float> RoverErrorLatitudeCache = new();
public readonly List<float> RoverErrorLongitudeCache = new();
public readonly List<float> RoverErrorAltitudeCache = new();
public readonly List<double> RoverBaselineCache = new();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If everything needs to be averaged/median calculated, wrap in struct member (GGA, GSA, GST...) field setters. It's not maintainable to store everything publicly accessible here.

@japsuu japsuu marked this pull request as draft October 21, 2024 06:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants