Skip to content

Commit

Permalink
Make the temperature miner a little safer.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepj committed Feb 10, 2020
1 parent 8fa197d commit dbe3951
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions Data Miners/XRGTemperatureMiner.m
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,17 @@ - (NSString *)unitsForLocation:(NSString *)location {
- (void)regenerateLocationKeyOrder {
NSArray *locations = [sensorData allKeys];
NSInteger numLocations = [locations count];
bool *alreadyUsed = calloc(numLocations, sizeof(bool));
int i;
if (numLocations == 0) return;

BOOL alreadyUsed[numLocations];

[locationKeysInOrder removeAllObjects];

for (i = 0; i < numLocations; i++) {
for (int i = 0; i < numLocations; i++) {
if (locations[i] == nil) {
alreadyUsed[i] = YES;
} else {
alreadyUsed[i] = NO;
}
}

Expand All @@ -239,7 +242,7 @@ - (void)regenerateLocationKeyOrder {
NSMutableArray *tmpDrive = [NSMutableArray arrayWithCapacity:3];
NSMutableArray *tmpOthers = [NSMutableArray arrayWithCapacity:3];

for (i = 0; i < numLocations; i++) {
for (int i = 0; i < numLocations; i++) {
if (alreadyUsed[i]) continue;

NSString *location = locations[i];
Expand Down Expand Up @@ -331,8 +334,8 @@ - (void)regenerateLocationKeyOrder {
}

// Loop through and add any left overs
for (i = 0; i < numLocations; i++) {
if (!alreadyUsed[i] & [sensorData[locations[i]][GSUnitsKey] isEqualToString:types[typeIndex]]) {
for (int i = 0; i < numLocations; i++) {
if ((!alreadyUsed[i]) & [sensorData[locations[i]][GSUnitsKey] isEqualToString:types[typeIndex]]) {
[tmpOthers addObject:locations[i]];
alreadyUsed[i] = YES;
}
Expand All @@ -354,8 +357,6 @@ - (void)regenerateLocationKeyOrder {
[locationKeysInOrder addObjectsFromArray:[tmpDrive sortedArrayUsingDescriptors:@[descriptor]]];
[locationKeysInOrder addObjectsFromArray:[tmpOthers sortedArrayUsingDescriptors:@[descriptor]]];
}

free(alreadyUsed);
}

- (float)currentValueForKey:(NSString *)locationKey {
Expand Down

0 comments on commit dbe3951

Please sign in to comment.