1
0
Fork 0

ADDED - Average speed per month in monthly traffic menu

master
Matthieu Lalonde 14 years ago
parent 3391af8ce5
commit 1652704543

@ -641,32 +641,64 @@
uint8_t count = [_transferData count];
NSMenuItem *monthlyMenu;
for (ii = 0; ii < count; ii++) {
if (ii > 0) {
[menuWanTraffic addItem:[NSMenuItem separatorItem]];
}
// Parse monthly transfer
NSDate *previousMonthDate = [self dateFromMonthsBack:ii];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *dateComp = [gregorian components:NSYearCalendarUnit | NSMonthCalendarUnit fromDate:previousMonthDate];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"M-yyyy"];
[dateFormat setDateFormat:@"MM-yyyy"];
uint64_t bytesIn = ([[[_transferData objectAtIndex:ii] objectAtIndex:0] longLongValue] * 1024 * 1024);
uint64_t bytesOut = ([[[_transferData objectAtIndex:ii] objectAtIndex:1] longLongValue] * 1024 * 1024);
NSString *strMonthtlyTitle = [NSString stringWithFormat:@"%@: %@/%@", [dateFormat stringFromDate:previousMonthDate], [self stringFromSize:bytesIn], [self stringFromSize:bytesOut]];
NSString *strMonthtlyTitle = [NSString stringWithFormat:@"%@\t%@/%@", [dateFormat stringFromDate:previousMonthDate], [self stringFromSize:bytesIn], [self stringFromSize:bytesOut]];
monthlyMenu = [[NSMenuItem alloc] initWithTitle:strMonthtlyTitle action:nil keyEquivalent:@""];
[menuWanTraffic addItem:monthlyMenu];
}
// Calculate average speed for the month
uint64_t secondsInMonth;
if (ii == 0) {
NSDateComponents *todayComp = [gregorian components:NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:[NSDate date]];
secondsInMonth = ([todayComp day] * 24 * 60 * 60) + ([todayComp hour] * 60 * 60) + ([todayComp minute] * 60) + [todayComp second];
} else {
NSCalendar* cal = [NSCalendar currentCalendar];
NSDateComponents* comps = [[[NSDateComponents alloc] init] autorelease];
[comps setMonth:[dateComp month]];
NSRange range = [cal rangeOfUnit:NSDayCalendarUnit
inUnit:NSMonthCalendarUnit
forDate:[cal dateFromComponents:comps]];
secondsInMonth = (range.length * 24 * 60 * 60);
}
- (void) populateMenuClients
{
/*
NSString * clientsStringData;
NSLog(@"%llu", secondsInMonth);
double speedIn = bytesIn / secondsInMonth;
double speedOut = bytesOut / secondsInMonth;
NSString *keyData = @"{arp_table::";
speedIn = round(2.2f * speedIn) / 2.2f;
speedOut = round(2.2f * speedOut) / 2.2f;
clientsStringData = [ _statusStringData substringFromIndex:([_statusStringData rangeOfString:keyData].location + [keyData length]) ];
clientsStringData = [ clientsStringData substringToIndex:[clientsStringData rangeOfString:@"}"].location ];
*/
NSString *strMonthtlyAvrg = [NSString stringWithFormat:@"\t\t\t%@/s %@/s", [self stringFromSpeed:speedIn], [self stringFromSpeed:speedOut]];
monthlyMenu = [[NSMenuItem alloc] initWithTitle:strMonthtlyAvrg action:nil keyEquivalent:@""];
[menuWanTraffic addItem:monthlyMenu];
[gregorian release];
}
}
- (void) populateMenuClients
{
NSString *clientsStringData = [wrt_request_client getKey:_statusStringData key:@"arp_table"];
// Remove any white spaces

Loading…
Cancel
Save