My question is a bit long. I really appreciate it if you could please read it all and I'd be very grateful for any piece of advice.
I have data related to 2 consumers as turtles who have rated laptops' features. The laptops have 2 kinds of features : size of the screen and battery life. Each has some levels. For example battery life has 5 hours, 12 hours, 24 hours, 30 hours. Data is stored in a csv file.
12 13.5 14 15 5 12 24 30
1 1 2 1 3 2 2 4 5
2 4 3 1 2 1 1 2 3
I want to sum the rates of 2 levels of feature. For example for consumer 1 and 2, what is:
sum rate of screen size of 13.5 + rate of battery life 24
Since 13.5 and 24 may change later and I want to know for example the sum of rates of size of 14 and battery life of 5, I defined two functions using "to-reports" . Also since for example the value "12" is in the header row twice and represents both a size and a battery life, I made 2 subsets of the csv file one for screen size , the other for battery.
12 13.5 14 15
1 1 2 1 3
2 4 3 1 2
5 12 24 30
1 2 2 4 5
2 1 1 2 3
First in the main program, the csv file is read and a turtle is assigned to each row, expecting to have two consumers.
to setup
ca
reset-ticks
file-close-all
file-open "turtle_details.csv"
let headerrow csv:from-row file-read-line
set Sc 13.5 ; at the beginning I want the rate of this screen size
set Bat 24
while [ not file-at-end? ] [
let data csv:from-row file-read-line
create-consumers 1 [
set shape "person"
set k k + 1
print obtain-Sc (Sc) + obtain-Bat (Bat)
]
]
file-close-all
end
I assumed, first, row one is read and a consumer is generated. Now it goes to to-report to find obtain-Screen(13.5) which is 2, but I thought next time that obrain_Screen is called, again the csv opens and the cursor would still be at the beginning, but I want it to read the second row. And to extend it, I might need it to go further and further. To solve this, I defined a counter k that for example the first time this condition is checked : idx = 0 < k =1 so the first row is read. Then idx = idx + 1 , so nothing else is done.
to-report obtain-Screen[Sc]
file-close-all ; close all open files
file-open "turtle_detailsSc.csv"
let headings csv:from-row file-read-line
ifelse is-number? position Sc headings
[
while [idx < k ]
[ set fdata csv:from-row file-read-line
set idx idx + 1
]
report item position Sc headings fdata
]
[report 0.000000009]
Something similar for Bat. But it does not work and has errors. Any ideas how to improve to-reports? Thanks
Edit
Considering the data set to be like this :
size12 size13.5 size14 size15 Battery5 Battery12 Battery24 Battery30
1 1 *2* 1 3 2 2 *4* 5
2 4 3 3 2 1 1 2 3
I can now access the data set and for each consumer find their evaluation of a laptop they have purchased. For example, consumer 1 has a laptop with size of 13.5 and battery life 24.
Consumer 1 evaluation of size 13.5 = 2
Consumer 1 evaluation of battery 24 = 4
Overall evaluation of laptop = 2 + 4 = 6
I have defined a procedure "Find Eval" that when I need to know the evaluation of different consumers, it enables me to access the dataset and find the values.
To explain the data in the table more, a consumer has a laptop so can evaluate it pretty well, but for other features like how he evaluates a laptop with the screen size of 15, he might have some exposure or just by hearing from others he has filled in the table.
I want to keep these 2 consumers and monitor their attitudes about laptop features during 20 years. In year 2, consumer 1 possibly updated his system, so now his battery life is 30. This time what I need to do is to access the dataset and calculate
Consumer 1 evaluation of size 13.5 = 2
plus
Consumer 1 evaluation of battery 30 = 5
Overall evaluation of laptop = 2 + 5 = 7
This time, I need to go to find the value for battery 30. I think when I repeat my code for 20 years, create-consumer will be repeated each time that I want to work with the dataset, so instead of keeping 2 consumers, each year, some new consumers will be created and the previous ones will be totally replaced.
The question is how I can create consumers once, but can access any data point in the data set for many times?
Thanks a lot,