-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathData_Processing.c
More file actions
95 lines (80 loc) · 2.12 KB
/
Data_Processing.c
File metadata and controls
95 lines (80 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <stdio.h>
#include <malloc.h>
int ** vector;
int nmbr_reg;
struct cloc_{
int hours;
int minutes;
int seconds;
};
typedef struct cloc_ * cloc;
void checker(int * minL,int * maxL, int * minT, int * maxT, int vector[6]);
int date_calculator(cloc start, cloc end,cloc to_check);
void calc(cloc start_time,cloc end_time,int results[6]){
int maxL=0,minL=0,maxT=0,minT=0,mediaL=0,mediaT=0,values_to_mean=0;
cloc curr_sample_time=malloc(sizeof(cloc));
for (int i =0;i<nmbr_reg;i++){
if(vector[i][6]!=0){//new entry
checker(&minL,&maxL,&minT,&maxT,vector[i]);
vector[i][6]=0;
}
curr_sample_time->hours=vector[i][0];
curr_sample_time->minutes=vector[i][1];
curr_sample_time->seconds=vector[i][2];
if(date_calculator(start_time,end_time,curr_sample_time)){
values_to_mean++;
mediaL+=vector[i][4];
mediaT+=vector[i][5];
}
}
mediaL/=values_to_mean;
mediaT/=values_to_mean;
results[0]=maxT;
results[1]=minT;
results[2]=mediaT;
results[3]=maxL;
results[4]=minL;
results[5]=mediaL;
free(curr_sample_time);
}
int date_calculator(cloc start, cloc end,cloc to_check){
if(to_check->hours < start->hours || to_check->hours > end->hours)
return 0;
if(to_check->hours != start-> hours && to_check->hours != end->hours)
return 1;
if(to_check->hours == start->hours){
if(to_check->minutes < start->minutes)
return 0;
if( to_check->minutes > start->minutes)
return 1;
else{
if(to_check->seconds < start->seconds)
return 0;
else
return 1;
}
}
if(to_check->hours == end->hours){
if(to_check->minutes > end->minutes)
return 0;
if( to_check->minutes < end->minutes)
return 1;
else{
if(to_check->seconds > end->seconds)
return 0;
else
return 1;
}
}
return 0;
}
void checker(int * minL,int * maxL, int * minT, int * maxT, int vector[6]){
if(vector[5]>=*maxT) //temp
* maxT=vector[5];
if(vector[5]<=*minT) //temp
* maxT=vector[5];
if(vector[4]>=*maxL) //lum
* maxL=vector[4];
if(vector[4]<=*maxL) //lum
* minL=vector[4];
}