Skip to content

Commit 5004a42

Browse files
rolled back populate_days
1 parent 0769ab1 commit 5004a42

3 files changed

Lines changed: 26 additions & 53 deletions

File tree

app.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pens,geojson,data/Farm AL_8.29.25.geojson,id,,,id," {
4141
]
4242
}
4343
]}"
44-
movement,csv,data/FarmAL.dataraw_subset.csv,ID,,DATE,," {
44+
movement,csv,data/Farm AL Centroid Data Cleaned 9.9.25.csv,ID,,DATE,," {
4545
""renderer"": {
4646
""type"": ""simple"",
4747
""symbol"": {

js/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ function setup_interface(_event_settings){
228228
if(obj.start!=null){
229229
record_manager.populate_days(event_data[obj.label],obj.start.trim(),obj.end,end_date)
230230
}
231+
console.log("event_data",event_data)
231232

232233
}
233234

js/record_manager.js

Lines changed: 24 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -427,66 +427,38 @@ class Record_Manager {
427427
}
428428
}
429429

430-
populate_days(result,_event_start,_event_end,_end_date){
430+
populate_days(_array,_event_start,_event_end,_end_date){
431431

432432
// called with event_data["sick"],"FLU","WELL",end_date)
433433
// create a sub set of the data
434434
//any record that has an EVENT labeled {_event_start} should have a record
435435
//console.log("populate_days", _end_date,_array)
436-
const data = this.json_data;
437-
const dateFormat = this.date_format;
438-
439-
440-
let prevRecord = null;
441-
442-
for (let i = 0; i < data.length; i++) {
443-
const t = data[i];
444-
const event = t["EVENT"].trim();
445-
const id = t["ID"];
446-
447-
// Precompute once (using Date.parse for speed)
448-
const startUnix = Date.parse(t["START DATE"]) / 1000;
449-
450-
// If the previous record is for the same ID and a start event,
451-
// and this one is the matching end event — close it.
452-
if (
453-
prevRecord &&
454-
prevRecord["ID"] === id &&
455-
prevRecord["EVENT"].trim() === _event_start &&
456-
event === _event_end
457-
) {
458-
459-
result.push({
460-
id,
461-
start_date: Date.parse(prevRecord["START DATE"]) / 1000,
462-
end_date: startUnix,
463-
from_pen: prevRecord["FROM PEN"],
464-
});
465-
prevRecord = null; // reset after closing
466-
} else {
467-
// If this is a new start event, remember it
468-
if (event === _event_start) {
469-
prevRecord = t;
436+
for(var i=0;i<this.json_data.length;i++){
437+
var t = this.json_data[i];
438+
439+
var end_date = false
440+
if(t["EVENT"].trim()==_event_start){
441+
442+
// find the end date which should be ahead
443+
if(_event_end && _event_end!=""){
444+
for(var j=i+1;j<this.json_data.length;j++){
445+
var u = this.json_data[j]
446+
// make sure the next event is later than the first and matches the desired end event name
447+
448+
if(u["ID"]==t["ID"] && u["EVENT"].trim()==_event_end && moment(t["START DATE"],this.date_format).unix() < moment(u["START DATE"],this.date_format).unix()){
449+
// console.log("Closing t",t, "with u",u)
450+
end_date=moment(u["START DATE"],this.date_format).unix()
451+
break;
452+
}
453+
}
454+
}
455+
if(!end_date){
456+
end_date=_end_date.unix()
457+
}
458+
_array.push({"id":t["ID"], "start_date": moment(t["START DATE"],this.date_format).unix(), "end_date": end_date,"from_pen": t["FROM PEN"]})
470459
}
471-
}
472-
}
473460

474-
// handle any unmatched start event (no end found)
475-
if (prevRecord) {
476-
var from_pen = prevRecord["FROM PEN"]
477-
478-
// if there is no from pen ... use the current pen
479-
if(from_pen === undefined){
480-
from_pen=prevRecord["IN PEN"]
481-
}
482-
result.push({
483-
id: prevRecord["ID"],
484-
start_date: Date.parse(prevRecord["START DATE"]) / 1000,
485-
end_date: _end_date.unix(),
486-
from_pen: from_pen,
487-
});
488461
}
489-
490462
}
491463
get_first_infection_date(){
492464
var infection_val=false

0 commit comments

Comments
 (0)