Skip to content

Commit 4d854a5

Browse files
authored
feat: adds direct seedings to sample database (#54)
Adds sample data for direct seeding events to the database.
1 parent 6600e6b commit 4d854a5

File tree

5 files changed

+151
-1
lines changed

5 files changed

+151
-1
lines changed

dist/db.sample.tar.gz

708 KB
Binary file not shown.

src/sampleDB/addDirectSeedings.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import { processCsvFile } from "../library/cvsUtil/csvUtil.js";
2+
import * as farmosUtil from "../library/farmosUtil/farmosUtil.js";
3+
import { lib as directSeeding } from "../library/directSeeding/lib.js";
4+
5+
import { basename, dirname } from "path";
6+
import { fileURLToPath } from "url";
7+
import { LocalStorage } from "node-localstorage";
8+
9+
/*
10+
* Set the name of the CSV file to be processed and the
11+
* messages to be printed before and after processing here.
12+
* The CSV file is assumed to be in the sampleData directory.
13+
*/
14+
const csv_file = "directSeedings.csv";
15+
const startMsg = "Adding direct seedings from " + csv_file + "...";
16+
const endMsg = "Direct seedings added.";
17+
18+
/*
19+
* Setup the information for connecting to the farmOS instance
20+
* in the FarmData2 development environment. Note: URL cannot
21+
* have a trailing /.
22+
*/
23+
const URL = "http://farmos";
24+
const client = "farm";
25+
const user = "admin";
26+
const pass = "admin";
27+
28+
/*
29+
* Get a local storage object that we'll use to simulate the
30+
* browser's localStorage and sessionStorage when running in node.
31+
*/
32+
let ls = new LocalStorage("scratch");
33+
34+
/*
35+
* Get a fully initialized and logged in instance of the farmOS.js
36+
* farmOS object that will be used to write assets, logs, etc.
37+
*/
38+
const farm = await farmosUtil.getFarmOSInstance(URL, client, user, pass, ls);
39+
40+
/*
41+
* Get any farmos id maps that we need for processing the data.
42+
*/
43+
//const usernameMap = await farmosUtil.getUsernameToUserMap(farm);
44+
45+
/*
46+
* Kick off the the pipeline that reads the csv file and passes
47+
* each row of data from the file to the processRow function.
48+
*/
49+
const data_file =
50+
dirname(fileURLToPath(import.meta.url)) + "/sampleData/" + csv_file;
51+
processCsvFile(data_file, processRow, startMsg, endMsg);
52+
53+
/*
54+
* Implement this function to processes each row of the CSV file.
55+
* The contents of the row arrive as an array with each entry being
56+
* a column from the line of the CSV file.
57+
*/
58+
async function processRow(row) {
59+
60+
// Split the location and bed names as necessary.
61+
const locationNames = row[2].split(";");
62+
const bedNames = locationNames.slice(1);
63+
64+
// Split the equipment names as necessary.
65+
let equipmentNames = [];
66+
if (row[6] != "") {
67+
equipmentNames = [... row[6].split(";")];
68+
}
69+
70+
let form = {
71+
seedingDate: row[0],
72+
cropName: row[1],
73+
locationName: locationNames[0],
74+
beds: bedNames,
75+
bedFeet: row[3],
76+
rowsPerBed: row[4],
77+
bedWidth: row[5],
78+
equipment: equipmentNames,
79+
depth: row[7],
80+
speed: row[8],
81+
comment: row[9],
82+
};
83+
84+
console.log(
85+
" Adding direct seeding on " +
86+
form.seedingDate +
87+
" for " +
88+
form.cropName +
89+
" in " +
90+
form.locationName +
91+
"..."
92+
);
93+
94+
await directSeeding.submitForm(form).catch((err) => {
95+
console.log(" " + err);
96+
});
97+
98+
console.log(" Added.");
99+
}

src/sampleDB/buildSampleDB.bash

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ node "$SCRIPT_DIR/addTraySeedings.js"
7373
error_check
7474
echo ""
7575

76+
# Add direct seedings
77+
node "$SCRIPT_DIR/addDirectSeedings.js"
78+
error_check
79+
echo ""
80+
7681
# Delete the authentication token if it exists.
7782
# Necessary because base DB was reinstalled so old token is not valid.
7883
echo "Deleting locally cached authentication token..."
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Sample Data for direct seedings.
2+
#
3+
# Format:
4+
#
5+
# Each line represents a direct seeding with the following comma delimited information:
6+
# "date","cropName","locationName;bed1;bed2;...","bedFeet","rowsPerBed","bedWidth","equipment1;equipment2;...","depth","speed","comment"
7+
#
8+
# Anything following a # on a line is a considered a comment.
9+
# Thus, names and descriptions cannot contain #
10+
# Blank Lines are ignored.
11+
12+
"2019-02-13","ARUGULA","A","100","1","60","Tractor;Seeding Drill","4","2","The only Arugula."
13+
14+
"2019-05-27","BEAN","A","90","2","48","Tractor;Seeding Drill","2","3","The first bean."
15+
"2019-06-24","BEAN","B","90","2","48","Tractor;Seeding Drill","2","3","Another bean."
16+
"2019-07-29","BEAN","C","90","3","48","Tractor;Seeding Drill","2","3","Another bean."
17+
"2019-08-05","BEAN","D","60","2","48","Tractor;Seeding Drill","2","3","The last bean."
18+
19+
"2019-03-25","HERB-CILANTRO","GHANA;GHANA-1","15","3","36","Portable Broadcaster","0","0","The first cilantro."
20+
"2019-04-19","HERB-CILANTRO","JASMINE","12","5","36","Portable Broadcaster","0","0",""
21+
"2019-05-22","HERB-CILANTRO","E","20","3","36","","","","No equipment."
22+
"2019-06-24","HERB-CILANTRO","F","30","3","36","","","","No equipment."
23+
"2019-07-02","HERB-CILANTRO","G","30","3","36","","","","No equipment."
24+
"2019-08-13","HERB-CILANTRO","E","30","3","36","","","","No equipment."
25+
"2019-09-04","HERB-CILANTRO","CHUAU;CHUAU-1","10","3","35","Portable Broadcaster","0","0","The last cilantro."
26+
27+
"2019-03-25","LETTUCE-MES MIX","GHANA;GHANA-3","88","3","36","Small Tractor;Planter","3","5","The first mes mix."
28+
"2019-04-12","LETTUCE-MES MIX","A","100","3","48","Tractor;Planter","3","5",""
29+
"2019-05-07","LETTUCE-MES MIX","A","123","3","48","Tractor;Planter","3","5",""
30+
"2019-06-05","LETTUCE-MES MIX","B","126","3","48","Tractor;Planter","3","5",""
31+
"2019-07-02","LETTUCE-MES MIX","B","99","3","46","Tractor;Planter","3","5",""
32+
"2019-08-05","LETTUCE-MES MIX","C","200","3","48","Tractor;Planter","3","5",""
33+
"2019-09-04","LETTUCE-MES MIX","CHUAU;CHUAU-2;CHUAU-3","88","5","36","Small Tractor;Planter","3","5",
34+
"2019-10-04","LETTUCE-MES MIX","CHUAU;CHUAU-4","88","5","36","Small Tractor;Planter","3","5",
35+
36+
"2019-05-29","POTATO-SWEET","E","1000","1","60","Tractor;Seeding Drill","4","2","The first sweet potato."
37+
"2019-06-06","POTATO-SWEET","E","230","1","60","Tractor;Seeding Drill","4","2","The first sweet potato."
38+
39+
"2019-02-04","RADISH","GHANA;GHANA-2","35","3","36","Small Tractor;Planter","2","1","The first radish."
40+
"2019-04-01","RADISH","GHANA;GHANA-4","100","5","36","Small Tractor;Planter","2","1",""
41+
"2019-05-02","RADISH","D","25","3","48","Tractor;Planter","2","4",""
42+
"2019-06-05","RADISH","E","25","3","48","Tractor;Planter","2","4",""
43+
"2019-08-05","RADISH","F","45","3","48","Tractor;Planter","2","4",""
44+
"2019-09-04","RADISH","CHUAU;CHUAU-5","35","3","36","Small Tractor;Planter","2","1","The last radish."
45+
46+
"2019-08-05","RADISH-DAIKON","G","44","3","36","Small Tractor;Planter","2","1","The only daikon radish."

src/sampleDB/sampleData/traySeedings.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"2019-07-26","BROCCOLI","JASMINE","2","288","1","Last broccoli tray seeding."
2222

2323
"2019-03-22","PEPPERS-BELL","JASMINE","6","128","1","First bell pepper tray seeding."
24-
"2019-04-12","PEPPERS-BELL","JASMINE","7","128","1","Last bell pepper tray seeding.",
24+
"2019-04-12","PEPPERS-BELL","JASMINE","7","128","1","Last bell pepper tray seeding."
2525

2626
"2019-04-12","HERB-BASIL","GHANA","3","96","1","First basil tray seeding."
2727
"2019-05-10","HERB-BASIL","CHUAU","4","200","1","Another basil tray seeding."

0 commit comments

Comments
 (0)