-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathotherFeature.cpp
183 lines (160 loc) · 4.04 KB
/
otherFeature.cpp
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include"library.h"
#include"OtherDataModel.h"
#include"dormparase.h"
#include"borrowParase.h"
#define SIZE 40000
#define LIBRARYFILE "C:\\Users\\root\\Desktop\\TensorFlow\\¾«×¼×ÊÖú\\train\\library_trainANSI.txt"
#define DORMFILE "C:\\Users\\root\\Desktop\\TensorFlow\\¾«×¼×ÊÖú\\train\\dorm_train.txt"
#define BORROWFILE "C:\\Users\\root\\Desktop\\TensorFlow\\¾«×¼×ÊÖú\\train\\borrow_train.txt"
#define OUTPUT "C:\\Users\\root\\Desktop\\TensorFlow\\¾«×¼×ÊÖú\\train\\OtherFeature1.txt"
using namespace std;
OtherDataModel* dataModel[SIZE];
int main(){
ifstream libraryFile = ifstream(LIBRARYFILE, ios::in | ios::binary);
ifstream dormFile = ifstream(DORMFILE, ios::in | ios::binary);
ifstream borrowFile = ifstream(BORROWFILE, ios::in | ios::binary);
ofstream of = ofstream(OUTPUT, ios::out | ios::binary);
if (!libraryFile || !dormFile || !borrowFile || !of){
cout << "file open fail" << endl;
return 0;
}
Date startDate;
Date globalDate;
Date endDate;
startDate.year = 2013;
startDate.mon = 9;
startDate.day = 1;
startDate.weekday = 7;
endDate.year = 2014;
endDate.mon = 9;
endDate.day = 1;
string str;
int cnt = 0;
globalDate = startDate;
//deal with library record
while (getline(libraryFile, str)){
Library lib(str);
//deal with library record
int id = lib.id;
Date date = lib.date;
//cout << id << " :";
//cout << date.year << date.mon << date.day << endl;
if (date.compare(globalDate) == -1){
cnt++;
continue;
}
while (!(globalDate == date)){
globalDate = globalDate.nextDay();
}
date.weekday = globalDate.weekday;
if (globalDate == endDate){
break;
}
if (dataModel[id] == NULL){
dataModel[id] = new OtherDataModel();
}
if (date.hour == -1){
cout << "phrase hour fail id: " << id << endl;
continue;
}
dataModel[id]->ioLibrary(date.mon, date.day, date.hour, date.weekday);
cnt++;
if ((cnt % 10000) == 0){
cout << "deal with library" << cnt << endl;
}
}
cnt = 0;
globalDate = startDate;
//deal with dorm record
while (getline(dormFile, str)){
Dorm dorm(str);
int id = dorm.id;
if (dorm.date.compare(globalDate) == -1){
cnt++;
continue;
}
while (!(globalDate == dorm.date)){
globalDate = globalDate.nextDay();
}
dorm.date.weekday = globalDate.weekday;
if (globalDate == endDate){
break;
}
if (dataModel[id] == NULL){
dataModel[id] = new OtherDataModel();
};
if (dorm.date.hour == -1){
cout << "dormio hour parase fail id: " << id << endl;
continue;
}
dataModel[id]->ioDorm(dorm.out, dorm.date.mon, dorm.date.hour, dorm.date.weekday);
cnt++;
if ((cnt % 10000) == 0){
cout << "deal with dorm" << cnt << endl;
}
}
cnt = 0;
globalDate = startDate;
//deal with borrow record
while (getline(borrowFile, str)){
Borrow bor(str);
int id = bor.id;
Date date = bor.date;
if (date.compare(globalDate) == -1){
cnt++;
continue;
}
while (!(globalDate == date)){
globalDate = globalDate.nextDay();
}
date.weekday = globalDate.weekday;
if (globalDate == endDate){
break;
}
if (dataModel[id] == NULL){
dataModel[id] = new OtherDataModel();
}
dataModel[id]->borrowBook(date.mon);
cnt++;
if ((cnt % 10000) == 0){
cout << "deal with borrow" << cnt << endl;
}
}
//output to file
for (int i = 0; i < SIZE; i++){
if (dataModel[i] != NULL){
of << i << ' ';
//output library
for (int j = 0; j < 12; j++){
of << dataModel[i]->getLibraryDay(j) << ' ';
}
for (int j = 0; j < 12; j++){
of << dataModel[i]->getLibraryNight(j) << ' ';
}
for (int j = 0; j < 12; j++){
of << dataModel[i]->getLibraryWeekend(j) << ' ';
}
//output dorm
for (int j = 0; j < 12; j++){
of << dataModel[i]->getDormNight(j) << ' ';
}
for (int j = 0; j < 12; j++){
of << dataModel[i]->getDormWeekend(j) << ' ';
}
//output borrow
for (int j = 0; j < 12; j++){
of << dataModel[i]->getBorrowNum(j) << ' ';
}
of << endl;
}
}
//close io
libraryFile.close();
dormFile.close();
borrowFile.close();
of.close();
}