Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
ffm-baseline
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ML
ffm-baseline
Commits
9faccb11
Commit
9faccb11
authored
Aug 15, 2018
by
张彦钊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add prints for test
parent
588e7f4c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
1 deletion
+8
-1
prepareData.py
prepareData.py
+5
-0
utils.py
utils.py
+3
-1
No files found.
prepareData.py
View file @
9faccb11
from
utils
import
con_sql
from
utils
import
con_sql
import
datetime
import
datetime
import
time
def
fetch_data
(
start_date
,
end_date
):
def
fetch_data
(
start_date
,
end_date
):
...
@@ -25,7 +27,10 @@ def fetch_data(start_date, end_date):
...
@@ -25,7 +27,10 @@ def fetch_data(start_date, end_date):
# 获取曝光表里的数据
# 获取曝光表里的数据
sql
=
"select cid,device_id,time,stat_date from data_feed_exposure "
\
sql
=
"select cid,device_id,time,stat_date from data_feed_exposure "
\
"where stat_date >= '{0}' and stat_date <= '{1}'"
.
format
(
start_date
,
end_date
)
"where stat_date >= '{0}' and stat_date <= '{1}'"
.
format
(
start_date
,
end_date
)
start
=
time
.
time
()
exposure
=
con_sql
(
sql
)
exposure
=
con_sql
(
sql
)
end
=
time
.
time
()
print
(
"获取曝光表耗时{}分"
.
format
((
end
-
start
)
/
60
))
exposure
=
exposure
.
rename
(
columns
=
{
0
:
"cid"
,
1
:
"device_id"
,
2
:
"time_date"
,
3
:
"stat_date"
})
exposure
=
exposure
.
rename
(
columns
=
{
0
:
"cid"
,
1
:
"device_id"
,
2
:
"time_date"
,
3
:
"stat_date"
})
print
(
"成功获取曝光表里的数据"
)
print
(
"成功获取曝光表里的数据"
)
# 从time特征中抽取hour
# 从time特征中抽取hour
...
...
utils.py
View file @
9faccb11
...
@@ -16,7 +16,7 @@ def get_date():
...
@@ -16,7 +16,7 @@ def get_date():
month
=
now
.
month
month
=
now
.
month
day
=
now
.
day
day
=
now
.
day
date
=
datetime
(
year
,
month
,
day
)
date
=
datetime
(
year
,
month
,
day
)
data_start_date
=
(
date
-
timedelta
(
days
=
3
6
))
.
strftime
(
"
%
Y-
%
m-
%
d"
)
data_start_date
=
(
date
-
timedelta
(
days
=
3
1
))
.
strftime
(
"
%
Y-
%
m-
%
d"
)
data_end_date
=
(
date
-
timedelta
(
days
=
1
))
.
strftime
(
"
%
Y-
%
m-
%
d"
)
data_end_date
=
(
date
-
timedelta
(
days
=
1
))
.
strftime
(
"
%
Y-
%
m-
%
d"
)
validation_date
=
(
date
-
timedelta
(
days
=
2
))
.
strftime
(
"
%
Y-
%
m-
%
d"
)
validation_date
=
(
date
-
timedelta
(
days
=
2
))
.
strftime
(
"
%
Y-
%
m-
%
d"
)
# 验证集和测试集的日期必须相差一天,否则切割数据集时会报错
# 验证集和测试集的日期必须相差一天,否则切割数据集时会报错
...
@@ -41,7 +41,9 @@ def con_sql(sql):
...
@@ -41,7 +41,9 @@ def con_sql(sql):
cursor
=
db
.
cursor
()
cursor
=
db
.
cursor
()
cursor
.
execute
(
sql
)
cursor
.
execute
(
sql
)
result
=
cursor
.
fetchall
()
result
=
cursor
.
fetchall
()
print
(
"成功从数据库获取数据"
)
df
=
pd
.
DataFrame
(
list
(
result
))
.
dropna
()
df
=
pd
.
DataFrame
(
list
(
result
))
.
dropna
()
print
(
"成功将数据转化成DataFrame"
)
db
.
close
()
db
.
close
()
return
df
return
df
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment