Moodle Course Total Grade - moodle

I want to display Course Total Grades like this:
if Quiz total = 1 then Course Total = 74
if Quiz total = 2 then Course Total = 74 again
if Quiz total = 3 then Course Total = 74 again
if Quiz total = 4 then Course Total = 77
if Quiz total = 5 then Course Total = 80
if Quiz total = 6 then Course Total = 83
...... and so on until Quiz total =34
I can't think of any formula that can give me the desired result.
Any suggestions on how to achieve that?
Can I change anything in the code maybe?

Do you require it to be actual value or just look like it? What I am trying to say is that you may probably be satisfied with standard functionality of Grade Letters

Related

How can I efficiently convert the output of one KDB function into three table columns?

I have a function that takes as input some of the values in a table and returns a tuple if you will - three separate return values, which I want to transpose into the output of a query. Here's a simplified example of what I want to achieve:
multiplier:{(x*2;x*3;x*3)};
select twoX:multiplier[price][0]; threeX:multiplier[price][1]; fourX:multiplier[price][2] from data;
The above basically works (I think I've got the syntax right for the simplified example - if not then hopefully my intention is clear), but is inefficient because I'm calling the function three times and throwing away most of the output each time. I want to rewrite the query to only call the function once, and I'm struggling.
Update
I think I missed a crucial piece of information in my explanation of the problem which affects the outcome - I need to get other data in the query alongside the output of my function. Here's a hopefully more realistic example:
multiplier:{(x*2;x*3;x*4)};
select average:avg price, total:sum price, twoX:multiplier[sum price][0]; threeX:multiplier[sum price][1]; fourX:multiplier[sum price][2] by category from data;
I'll have a go at adapting your answers to fit this requirement anyway, and apologies for missing this bit of information. The real function if a proprietary and fairly complex algorithm and the real query has about 30 output columns, hence the attempt at simplifying the example :)
If you're just looking for the results themselves you can extract (exec) as lists, create dictionary and then flip the dictionary into a table:
q)exec flip`twoX`threeX`fourX!multiplier[price] from ([]price:til 10)
twoX threeX fourX
-----------------
0 0 0
2 3 4
4 6 8
6 9 12
8 12 16
10 15 20
12 18 24
14 21 28
16 24 32
18 27 36
If you need other columns from the original table too then its trickier but you could join the tables sideways using ,'
q)t:([]price:til 10)
q)t,'exec flip`twoX`threeX`fourX!multiplier[price] from t
An apply # can also achieve what you want. Here data is just a table with 10 random prices. # is then used to apply the multiplier function to the price column while also assigning a column name to each of the three resulting lists:
q)data:([] price:10?100)
q)multiplier:{(x*2;x*3;x*3)}
q)#[data;`twoX`threeX`fourX;:;multiplier data`price]
price twoX threeX fourX
-----------------------
80 160 240 240
24 48 72 72
41 82 123 123
0 0 0 0
81 162 243 243
10 20 30 30
36 72 108 108
36 72 108 108
16 32 48 48
17 34 51 51

Calculating the weighted moving average of 2 lists using a set window

If I have two lists:
a:1 2 3 4;
b:10 20 30 40;
I want to sum the product of the two lists within a window of 2. So the result set should be:
10 50 130 250
For example, to get the result of 130 it would be (2*20)+(3*30) = 130
sums 2 mavg '(a*b)
seems to get me part way there, but the window of 2 isn't being applied. I've tried experimenting with sum, sums, sum each, wavg, mavg, etc. and I am completely stuck. Could anyone help? Thanks!
This line should work for you:
2 msum a*b
as demonstrated here:
q)a:1 2 3 4
q)b:10 20 30 40
q)2 msum a*b
10 50 130 250
For more information about the keyword msum, you could check out the Kx Reference page:
https://code.kx.com/wiki/Reference/msum
Hope that helps!
Alternatively you could use the adverb each prior:
q)+':[a*b]
However this will only work with a window size of 2 and if your data contains null values this needs to be padded with 0:
q)+':[0^a*b2]
On a positive note it is faster than using msum in this situation.
q)\ts:1000000 +':[0^a*b2]
940 1264
q)\ts:1000000 2 msum a*b2
1556 1104

Matlab programming, Matrix sorting and ranking

Consider an example given below. There are 3 customers A, B,C.
1st row of matrix is the demand of respective customer and second row is the day when they need.
for example: demand A=[10,40,50;15,45,75]; Customer A needs 10 items on 15th day.. 40 items on 45th day and 50 items on 75th day..Similarly for B,C.
demand A=[10,40,50;15,45,75];
demand B=[80,30,20;05,35,80];
demand C=[50,40,30;20,47,88];
Now i need to rank the customer on basis of days. So here answer should be like
rank 1: 5th day customer B 80 items
rank 2: 15th day customer A 10 items
rank 3: 20th day customer C 50 items.
and so on.
How can i do it in mat lab. so that when i rank it on basis of the day then I should then know how many items and which customer accordingly.
output should be like this:
Rank Customer items day
1 B 80 05
2 A 10 15
3 C 50 20
4 B 30 35
5 A 40 45
6 C 40 47
7 A 40 75
8 B 20 80
9 C 30 88
I suggest the following approach:
First stage
generates a new matrix, which is the composition of A,B and C, such that:
The first col represents the day.
The second col represents the requested amount.
The third col is the costumer index (A=1,B=2,C=3).
res = [A',ones(size(A',1),1);B',ones(size(A',1),1)*2;C',ones(size(C',1),1)*3];
res(:,[2,1]) = res(:,[1,2]);
Second stage
sort the matrix according to the first column, which represents the day
[~,sortedDaysIndices] = sort(res(:,1));
res = res(sortedDaysIndices,:);
Third stage: print the results
for ii=1:size(res)
if res(ii,3)==1
costumerStr = 'A';
elseif res(ii,3)==2
costumerStr = 'B';
else
costumerStr = 'C';
end
fprintf('%s\n',[num2str(ii) ' ' costumerStr ' ' num2str(res(ii,2)) ' ' num2str(res(ii,1))])
end
Result
1 B 80 5
2 A 10 15
3 C 50 20
4 B 30 35
5 A 40 45
6 C 40 47
7 A 50 75
8 B 20 80
9 C 30 88

Creating a matrix for a given value of a given value - For loop issues

I'm not sure if the title is very clear.
What I am trying to do is analyze a huge amount of data and produce a singular matrix for each ID.
The data comes in the form:
1001 00101 150
1001 00102 146
1001 00103 145
......
1001 19401 178
1001 19402 194
ID(1:4) Day(6:8) Half hour within a 24 hour period (9:10) Usage(12:end)
e.g ID=1001 Day=001 Half Hour=01 Usage=150
The ID, Day and Half hour values follow a strict pattern however the usage is the measured value.
I am trying to output
ID Value - Average usage per half hour
1001 01 150
1001 02 160
1001 03 173
1001 04 194
.... .. ...
1001 48 150
.... .. ...
1100 48 147
I've broken down the data into each specific component, however I am having trouble outputting the data into the average usage for each half hour, constantly getting trapped in for loops with no end product.
My base code currently examines the first line and extracts each component
fid = fopen('test.txt');
tline = fgetl(fid);
ID=tline(1:4);
disp(ID);
Day=tline(6:8);
disp(Day);
HalfHour=tline(9:10);
disp(HalfHour);
Usage=tline(12:end);
disp(Usage);
However I am really struggling to amplify this to the entire data set and produce the specified output.
Any help would be much appreciated.

Matlab simulation: Query regarding generating random numbers

I am doing some simulations studies and for initial stuides I am trying to simulate 100 gas particles and then grouping of these gas particles in 5 groups randomly for 10 or 100 times (non zero values in any groups). after that i have to find the group with highest particle and the number.
for example
100 gas particles
1 2 3 4 5(groups) Total particle group/Highest number
20|20|20|20|20 100 1-2-3-4-5/20
70|16|04|01|09 100 1/70
18|28|29|10|15 100 3/29
.
.
etc
i have used this to generate 5 random numbers for a single time
for i=1:1
randi([1,100],1,5)
end
ans =
50 41 9 60 88
but how will i find the highest number and group?
Use the max function :
a = [50 41 9 60 88];
[C,I] = max(a)
C should be equal to 88 and I to 4.
For the special case of equality (first line in your code), you have to read the documentation to see the result of max. I think the index returned will be the first max.