forked from megha89/AnomalyDetection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_matrix.m
84 lines (77 loc) · 3.02 KB
/
gen_matrix.m
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
%%This file is Copyright (C) 2018 Megha Gaur.
clc; clear all;
%addpath C:\Users\Angshul\Documents\MATLAB\AnomalyDetection\Peccan_dataset
addpath C:\Users\mgaur\Documents\MATLAB\MetricEvaluation\Dataset
filepath = 'C:\Users\mgaur\Documents\MATLAB\MetricEvaluation\Dataset\Electricity_P';
%filepath = 'C:\Users\Angshul\Documents\MATLAB\AnomalyDetection\test';
filename = dir(fullfile(filepath,'*.csv'));
files = {filename.name}'; %'# file names
num = numel(files);
hourly_meter_data = 0;
count = 1;
col = 0;
for i = 5:5
str = (files{i});
filename = fullfile(filepath,str);
fileID = fopen(filename,'r');
%F = textscan(fileID,'%s %*f %*f %*f %*f %*f %*f %*f %*f %*f %*f %*f %*f %*f %*f %f %*[^\n]','Delimiter',{',';'\n'},'HeaderLines',1);
F = textscan(fileID,'%s %*f %*f %*f %*f %*f %*f %*f %*f %f %*[^\n]','Delimiter',{',';'\n'},'HeaderLines',1);
timestamp = F{1};
fridge_data = F{2};
k = 0;
%Check for files with 1 month of data
rows = size(timestamp,1)
no_months = round((rows/1440)/30);
col = col+1;
IndexS = strfind(timestamp,'2014-04-01 00:00:00-05:00');
IndexE = strfind(timestamp,'2014-05-30 23:59:00-05:00');
Index1 = find(not(cellfun('isempty', IndexS)));
Index2 = find(not(cellfun('isempty', IndexE)));
for j = Index1:Index2
[date] = strsplit(timestamp{j,:});
[DayNumber,DayName] = weekday(date{1});
%if DayName == 'Mon' | DayName == 'Tue' | DayName == 'Wed' | DayName == 'Thu' | DayName == 'Fri'
if DayName == 'Sat' | DayName == 'Sun'
if count <= 60
hourly_meter_data = hourly_meter_data + fridge_data(j,:);
agg_meter_data = floor(hourly_meter_data/(count));
%k = k+1;
%weekend_data{k,col} = agg_meter_data;
count = count+1;
if count == 61
k = k+1;
appliance_data{k,col} = agg_meter_data;
count = 1;
hourly_meter_data = 0;
end
else
k = k+1;
if j > 60
hourly_timestamp = timestamp{j-60,:};
% weekend_data{k,col} = hourly_timestamp;
appliance_data{k,col} = agg_meter_data;
count = 1;
hourly_meter_data = 0;
else
hourly_timestamp = timestamp{j,:};
%weekend_data{k,col} = hourly_timestamp;
appliance_data{k,col} = agg_meter_data;
count = 1;
hourly_meter_data = 0;
end
end
end
end
disp(filename)
end
fclose(fileID);
%save('fridge_data.mat','appliance_data')
%
% % fileID = fopen('weekendData1.dat','w');
% % formatSpec = '%s %d\n';
% % [nrows,ncols] = size(weekend_data);
% % for row = 1:nrows
% % fprintf(fileID,formatSpec,weekend_data{row,:});
% % end
% % fclose(fileID);
%