mirror of
https://github.com/CovidBraceletPrj/CovidBracelet.git
synced 2024-12-05 00:55:43 +01:00
Contacts: Remove unneeded function for retrieving infected keys for period
This commit is contained in:
parent
4399810691
commit
ad4dcd013e
@ -54,77 +54,23 @@ int register_record(record_t* record) {
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_number_of_infected_for_period(ENPeriodKey* key, time_t timestamp) {
|
int get_number_of_infected_for_multiple_intervals(infected_for_period_key_ctx_t* ctx, int count) {
|
||||||
ENPeriodIdentifierKey periodIdentifier;
|
|
||||||
en_derive_period_identifier_key(&periodIdentifier, key);
|
|
||||||
|
|
||||||
ENIntervalNumber intervalStart = en_get_interval_number_at_period_start(timestamp);
|
|
||||||
|
|
||||||
// derive all interval identifiers
|
|
||||||
ENIntervalIdentifier intervals[EN_TEK_ROLLING_PERIOD];
|
|
||||||
for (int i = 0; i < EN_TEK_ROLLING_PERIOD; i++) {
|
|
||||||
en_derive_interval_identifier(&intervals[i], &periodIdentifier, intervalStart + i);
|
|
||||||
}
|
|
||||||
|
|
||||||
time_t end_ts = timestamp + 3600 * 24;
|
|
||||||
record_iterator_t iterator;
|
record_iterator_t iterator;
|
||||||
int rc = ens_records_iterator_init_timerange(&iterator, ×tamp, &end_ts);
|
for (int i = 0; i < count; i++) {
|
||||||
if (rc) {
|
int rc = ens_records_iterator_init_timerange(&iterator, &ctx[i].search_start, &ctx[i].search_end);
|
||||||
return rc;
|
if (rc) {
|
||||||
}
|
return rc;
|
||||||
printk("init iterator between %d and %d\n", iterator.current.sn, iterator.sn_end);
|
}
|
||||||
|
while (!iterator.finished) {
|
||||||
uint64_t infected = 0;
|
if (memcmp(&iterator.current.rolling_proximity_identifier, &ctx[i].interval_identifier,
|
||||||
while (!iterator.finished) {
|
|
||||||
// printk("new contact\n");
|
|
||||||
for (int i = 0; i < EN_TEK_ROLLING_PERIOD; i++) {
|
|
||||||
// printk("new period");
|
|
||||||
if (memcmp(&iterator.current.rolling_proximity_identifier, &intervals[i],
|
|
||||||
sizeof(iterator.current.rolling_proximity_identifier)) == 0) {
|
sizeof(iterator.current.rolling_proximity_identifier)) == 0) {
|
||||||
// we found a match
|
ctx[i].infected++;
|
||||||
infected++;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
ens_records_iterator_next(&iterator);
|
||||||
ens_records_iterator_next(&iterator);
|
|
||||||
}
|
|
||||||
return infected;
|
|
||||||
}
|
|
||||||
|
|
||||||
void get_number_of_infected_for_multiple_periods(infected_for_period_key_ctx_t* ctx, time_t timestamp, int count) {
|
|
||||||
// for (int i = 0; i < count; i++) {
|
|
||||||
// ctx[i].infected = get_contacts_for_period_key(ctx[i].key, timestamp);
|
|
||||||
// }
|
|
||||||
|
|
||||||
ENIntervalIdentifier intervals[count][EN_TEK_ROLLING_PERIOD];
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
ENIntervalNumber intervalStart = en_get_interval_number_at_period_start(timestamp);
|
|
||||||
for (int j = 0; j < EN_TEK_ROLLING_PERIOD; j++) {
|
|
||||||
en_derive_interval_identifier(&intervals[i][j], &ctx[i].key, intervalStart + j);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
// init iterator
|
|
||||||
time_t end_ts = timestamp + 3600 * 24;
|
|
||||||
record_iterator_t iterator;
|
|
||||||
int rc = ens_records_iterator_init_timerange(&iterator, ×tamp, &end_ts);
|
|
||||||
if (rc) {
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
printk("init iterator between %d and %d\n", iterator.current.sn, iterator.sn_end);
|
|
||||||
|
|
||||||
while (!iterator.finished) {
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
for (int j = 0; j < EN_TEK_ROLLING_PERIOD; j++) {
|
|
||||||
if (memcmp(&iterator.current.rolling_proximity_identifier, &intervals[i][j],
|
|
||||||
sizeof(iterator.current.rolling_proximity_identifier)) == 0) {
|
|
||||||
ctx[i].infected++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ens_records_iterator_next(&iterator);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup_test_data() {
|
void setup_test_data() {
|
||||||
@ -142,12 +88,13 @@ void setup_test_data() {
|
|||||||
// create infected record which
|
// create infected record which
|
||||||
record_t infectedRecord;
|
record_t infectedRecord;
|
||||||
infectedRecord.timestamp = i * EN_INTERVAL_LENGTH;
|
infectedRecord.timestamp = i * EN_INTERVAL_LENGTH;
|
||||||
en_derive_interval_identifier(&infectedRecord.rolling_proximity_identifier, &infectedPik, i);
|
en_derive_interval_identifier((ENIntervalIdentifier*)&infectedRecord.rolling_proximity_identifier, &infectedPik,
|
||||||
|
i);
|
||||||
record_t dummyRecord;
|
record_t dummyRecord;
|
||||||
en_derive_interval_identifier(&dummyRecord.rolling_proximity_identifier, &dummyPik, i);
|
en_derive_interval_identifier((ENIntervalIdentifier*)&dummyRecord.rolling_proximity_identifier, &dummyPik, i);
|
||||||
int rc;
|
int rc;
|
||||||
if (i % 3 == 0) {
|
if (i % 3 == 0) {
|
||||||
if (rc = add_record(&infectedRecord)) {
|
if ((rc = add_record(&infectedRecord))) {
|
||||||
printk("err %d\n", rc);
|
printk("err %d\n", rc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,7 +103,7 @@ void setup_test_data() {
|
|||||||
|
|
||||||
for (int j = 0; j < EN_INTERVAL_LENGTH / spread; j++) {
|
for (int j = 0; j < EN_INTERVAL_LENGTH / spread; j++) {
|
||||||
dummyRecord.timestamp = i * EN_INTERVAL_LENGTH + j * spread + 1;
|
dummyRecord.timestamp = i * EN_INTERVAL_LENGTH + j * spread + 1;
|
||||||
if (rc = add_record(&dummyRecord)) {
|
if ((rc = add_record(&dummyRecord))) {
|
||||||
printk("err %d\n", rc);
|
printk("err %d\n", rc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -173,7 +120,7 @@ void setup_test_data() {
|
|||||||
timing_start();
|
timing_start();
|
||||||
start_time = timing_counter_get();
|
start_time = timing_counter_get();
|
||||||
|
|
||||||
printk("found %d infected\n", get_number_of_infected_for_period(&infectedPeriodKey, 200));
|
// printk("found %d infected\n", get_number_of_infected_for_period(&infectedPeriodKey, 200));
|
||||||
|
|
||||||
end_time = timing_counter_get();
|
end_time = timing_counter_get();
|
||||||
|
|
||||||
|
@ -16,8 +16,10 @@
|
|||||||
#include "exposure-notification.h"
|
#include "exposure-notification.h"
|
||||||
|
|
||||||
typedef struct infected_for_period_key_ctx {
|
typedef struct infected_for_period_key_ctx {
|
||||||
ENPeriodKey* key;
|
ENIntervalIdentifier* interval_identifier;
|
||||||
int infected;
|
int infected;
|
||||||
|
time_t search_start;
|
||||||
|
time_t search_end;
|
||||||
} infected_for_period_key_ctx_t;
|
} infected_for_period_key_ctx_t;
|
||||||
|
|
||||||
void print_key(_ENBaseKey* key);
|
void print_key(_ENBaseKey* key);
|
||||||
@ -43,13 +45,15 @@ int register_record(record_t* record);
|
|||||||
int get_number_of_infected_for_period(ENPeriodKey* key, time_t timestamp);
|
int get_number_of_infected_for_period(ENPeriodKey* key, time_t timestamp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the number of infected records for multiple PeriodKeys.
|
* Get the number of infected records for multiple IntervalIdentifier.
|
||||||
*
|
*
|
||||||
* @param ctx array of period keys and timestamps with field "infected" for the number of infected records
|
* @param ctx array of period keys and timestamps with field "infected" for the number of infected records
|
||||||
* @param timestamp the timestamp of the period
|
* @param timestamp the timestamp of the period
|
||||||
* @param count the number of periods in the array
|
* @param count the number of periods in the array
|
||||||
|
*
|
||||||
|
* @returns 0 in case of success, -ERRNO in case of an error
|
||||||
*/
|
*/
|
||||||
void get_number_of_infected_for_multiple_periods(infected_for_period_key_ctx_t* ctx, time_t timestamp, int count);
|
int get_number_of_infected_for_multiple_intervals(infected_for_period_key_ctx_t* ctx, int count);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup fixed test data for storage.
|
* Setup fixed test data for storage.
|
||||||
|
Loading…
Reference in New Issue
Block a user