Arrays in raptor - arrays

How can I store an array in my raptor program so I can refer to it for the entire program?
This is what the program's output should look like:
Day Calories Consumed Calories Burned
Monday 2600 150
Tuesday 2400 100

Create a class with three properties
day
caloriesConsumed
caloriesBurned
Declare a property in your controller
private Result result;
After serialize a list of objects in your controller.
result.include("listObjects", List< YourObject >);

Related

Average for loop in loop PL / SQL

I am trying to calculate the avarage of durations from the last 40 days for diffrent IDs.
Example: I have 40 days and for each day IDs from 1-20 and each ID has a start date and end date in HH:MI:SS.
My code is a cursor which fetches the last 40 days, then I made a second for loop. In this one I select all the ids from this day. Then I go through every ID for this day and select start and end dat calculating the duration. So far so good. But how do I calculate the avarage of the duration for the IDs in the last 40 days.
The idea is simple. To take the durations for one id (in the last 40 days) add them together and divide them by 40. And then do the same for all IDs. My plan was to make a 2d Array and in the first array putting all IDs, then in the second array to put the duration and add the values for one id together. Then I would have added all the durations for one ID together and get the value from the array. But I am kinda stuck in that idea.
I also wonder if there is a better solution.
Thanks for any help!
From my point of view, you don't need loops nor PL/SQL - just calculate the average:
select id,
avg(end_date - start_date)
from your_table
where start_date >= trunc(sysdate) - 40
group by id
Drawback might be what you said - that you stored dates as hh:mi:ss. What does it mean? That you stored them as strings? If so, most probably bad idea; dates (as Oracle doesn't have a separate datatype for time) should be stored into DATE datatype columns.
If you really have to work with strings, then convert them to dates:
avg(to_date(end_date, 'hh:mi:ss') - to_date(start_date, 'hh:mi:ss'))
Also, you'll then have to have another DATE datatyp column which is capable of saying what "last 40 days" actually means.
Result (the average) will be number of days between these values. Then you can format it prettier, if you want.

How to transform a table into text file in file operation?

I'm new to file operation and I want to insert data from this table into a text file. How can I do it?
Let's say if my table is in below:
Deal & Promotion
Option
Detail
Card Price (include initial store value)
Reload
Total Payment
My30
-
30 days
-
30
30
MyCity
1 day
Reload
-
5
5
MyCity
1 day
First time
10
5
15
MyCity
3 days
Reload
-
15
15
MyCity
3 days
First time
10
15
25
Concession Card
Student
Fare discount 50%
15
(user define values)
Minimum reload: 15(user define values)
Concession Card
Senior Citizen
Fare discount 50%
15
(user define values)
Minimum reload: 15(user define values)
Concession Card
Disability
Fare discount 50%
15
(user define values)
Minimum reload: 15(user define values)
Let say if I want to transform all of them to a text file like this:
FILE *input;
input = fopen("pricelist.txt","w");
fprintf(input,"My30 30Days FirstTime&Reload 30.00\nMyCity 1Day Reload 5.00\nMyCity 1Day FirstTime 15.00\nMyCity 3Days Reload 15.00\nMyCity 3Days FirstTime 25.00\nConcessionCard Student Benefit50%% >=15.00\nConcessionCard SeniorCitizen Benefit50%% >=15.00\nConcessionCard OKU Benefit50%% >=15.00");
fclose(input);
The example text file that I have build is like this:
I cannot enter spacing for 2 words so I stick them together. Is there any other way to insert those data similar to the table above?
After transforming all the data into the text file how can I call or passing these data or values in my coding later on?
You can create a serialization and deserialization method in your program so that when you write or read the text file, it will keep the table format.
Serialization: You will write the file, in a specific order, using separators in the middle of the values.
Deserialization: You will read the file, detecting the separators dinamically, and assigning the values, in the same order you wrote them, to a matrix.

iterating over multindex - a groupby.value_counts() object is only through values and not through original date index

i want to know the percent of males in the ER (emergency room) during days that i defined as over crowded days.
i have a DF named eda with rows repesenting each entry to the ER. a certain column states if the entry occurred in an over crowded day (1 means over crowded) and a certain column states the gender of the person who entered.
so far i managed to get a series of over crowded days as index and a sub-index representing gender and the number of entries in that gender.
i used this code :
eda[eda.over_crowd==1].groupby(eda[eda.over_crowd==1].index.date).gender.value_counts()
and got the following result:
my question is, what is the most 'pandas-ian' way to get the percent of males\females in general. or, how to continue from the point i stopped?
as can be shown in the bottom of the screenshot, when i iterate over the elements, each value is the male of female consecutively. i want to iterate over dates so i could somehow write a more clean loop that will produce another column of male percentage.
i found a pretty elegant solution. i'm sure there are more, but maybe it can help someone else.
so i defined a multi-index series with all dates and counts of females and males. then used .loc to operate on each count of all dates to get percentage of males at each day. finally i just extract only the days that apply for over_crowd==1.
temp=eda.groupby(eda.index.date).gender.value_counts()
crowding['male_percent']=np.divide(100*temp.loc[:,1],temp.loc[:,2]+temp.loc[:,1])
crowding.male_percent[crowding.over_crowd==1]

Time Range restriction on OWL

We have a class CBSTV, which has some subclasses like News, Documentary, and etc. The data property time will specify the time of each program. For example, the news is every day between 16:00:00-17:00:00. I tried to represent this restriction this way:
dateTime [>= T16:00:00Z, <=T17:00:00Z ]
but, it is wrong, anyone know the correct way to represent this
also, we have another data property duration. For instance the duration of the news is between 45 minutes to one hour. I don't know how I should represent this one too?
The datatype for recurring times (e.g., 17:00 every day) is not xsd:dateTime but xsd:time

How to make a single array space with a date in it return the day of the week

I'm working on a spreadsheet that will keep track of attendance violations for employees.
I have an array called BoxA and it will be filled with dates. I would like a report to be written where a cell from the array is called twice, but once to return the day of the week, and the second time to return the actual date that is in the cell. The goal is a line in the report that reads:
Sunday, 8/24/2014 John was absent.
Is there a way to format the Array. I don't mind creating a second array based on the first that is formatted differently, but I can't seem to figure out how to make the array return the day of the week when it consists only of dates.
Thank you in advance.
motizer
With a date in A1, in another cell enter:
=TEXT(A1,"dddd mm/dd/yyyy") & " John was absent"

Resources