Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
QM_TJ
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李增强
QM_TJ
Commits
5506a457
Commit
5506a457
authored
Jan 25, 2021
by
李增强
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
m
parent
597c9cde
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
133 additions
and
93 deletions
+133
-93
lib/qm_tj.dart
lib/qm_tj.dart
+15
-93
lib/src/tj/exposure.dart
lib/src/tj/exposure.dart
+58
-0
lib/src/tj/tap.dart
lib/src/tj/tap.dart
+60
-0
No files found.
lib/qm_tj.dart
View file @
5506a457
...
@@ -5,15 +5,18 @@ import 'dart:convert';
...
@@ -5,15 +5,18 @@ import 'dart:convert';
import
'package:qm_tj/src/utils.dart'
;
import
'package:qm_tj/src/utils.dart'
;
import
'src/db.dart'
;
import
'src/db.dart'
;
import
'src/http.dart'
;
import
'package:crypto/crypto.dart'
as
crypto
;
import
'package:crypto/crypto.dart'
as
crypto
;
import
'src/tj/app.dart'
;
import
'src/tj/app.dart'
;
import
'src/tj/page.dart'
;
import
'src/tj/page.dart'
;
import
'src/tj/tap.dart'
;
import
'src/tj/exposure.dart'
;
class
QMTJ
{
class
QMTJ
{
static
DB
_db
;
static
DB
_db
;
static
App
_app
;
static
App
_app
;
static
Page
_page
;
static
Page
_page
;
static
Tap
_tap
;
static
Exposure
_exposure
;
static
void
debug
()
{
static
void
debug
()
{
Utils
.
debug
();
Utils
.
debug
();
...
@@ -23,9 +26,14 @@ class QMTJ {
...
@@ -23,9 +26,14 @@ class QMTJ {
_db
=
DB
();
_db
=
DB
();
_app
=
App
(
_db
);
_app
=
App
(
_db
);
_page
=
Page
(
_db
);
_page
=
Page
(
_db
);
_tap
=
Tap
(
_db
);
_exposure
=
Exposure
(
_db
);
_db
.
init
();
_db
.
init
();
Future
.
delayed
(
Duration
(
seconds:
5
)).
then
((
value
)
{
Future
.
delayed
(
Duration
(
seconds:
5
)).
then
((
value
)
{
uploadPageTj
();
_app
.
upload
();
_page
.
upload
();
_tap
.
upload
();
_exposure
.
upload
();
});
});
}
}
...
@@ -56,24 +64,8 @@ class QMTJ {
...
@@ -56,24 +64,8 @@ class QMTJ {
/// [clickId] 点击id
/// [clickId] 点击id
/// [extras] 点击参数
/// [extras] 点击参数
static
void
tap
(
static
void
tap
(
{
int
source
,
{
String
pageId
,
String
clickId
,
Map
<
String
,
dynamic
>
extras
})
async
{
String
pageId
,
_tap
.
onTap
(
pageId:
pageId
,
clickId:
clickId
,
extras:
extras
);
String
clickId
,
Map
<
String
,
dynamic
>
extras
})
async
{
// int clickTime = _getDateNow();
// String extrasStr = json.encode(extras);
// String id = _md5("${pageId}_${clickId}_${extrasStr}_${clickTime}");
// Map<String, dynamic> map = {
// "id": id,
// "source": source,
// "page_id": pageId,
// "click_id": clickId,
// "click_time": clickTime,
// "extras": extrasStr,
// };
// await _db.ready;
// log("tap", map);
// await _db.db.insert("tap_tj", map);
}
}
/// 曝光
/// 曝光
...
@@ -81,78 +73,8 @@ class QMTJ {
...
@@ -81,78 +73,8 @@ class QMTJ {
/// [exposureId] 曝光id
/// [exposureId] 曝光id
/// [extras] 曝光参数
/// [extras] 曝光参数
static
void
exposure
(
static
void
exposure
(
{
int
source
,
{
String
pageId
,
String
exposureId
,
Map
<
String
,
dynamic
>
extras
})
async
{
String
pageId
,
_exposure
.
onExposure
(
String
exposureId
,
pageId:
pageId
,
exposureId:
exposureId
,
extras:
extras
);
Map
<
String
,
dynamic
>
extras
})
async
{
// int exposureTime = _getDateNow();
// String extrasStr = json.encode(extras);
// String id = _md5("${pageId}_${exposureId}_${extrasStr}_${exposureTime}");
// Map<String, dynamic> map = {
// "id": id,
// "source": source,
// "page_id": pageId,
// "exposure_id": exposureId,
// "exposure_time": exposureTime,
// "extras": extrasStr,
// };
// await _db.ready;
// log("exposure", map);
// await _db.db.insert("exposure_tj", map);
}
// 上传页面统计
static
void
uploadPageTj
()
async
{
// await _db.ready;
// List<Map> list = await _db.db.query("page_tj", limit: 100, offset: 0);
// if (list.length == 0) {
// return;
// }
// List<String> ids = [];
// list = list.map((e) {
// var item = {
// "app_version": '0.0.1',
// "app_channel": "APP渠道",
// "devices_id": '3A26610FFE43D5838DDE7A40BA2E3E2C',
// "inter": '4G',
// "source": e['source'],
// "page_id": e['page_id'],
// "last_page_id": e['last_page_id'],
// "come_time": e['appear_time'],
// "out_time": e['disappear_time'],
// "extras": json.decode(e['extras'])
// };
// ids.add(e['id']);
// Map project = {
// "event_name": "page_scan",
// "app": "xx",
// "event_info": item
// };
// return project;
// }).toList();
// print({"project": json.encode(list)});
// }
// static Map<String, dynamic> getCommonParams() {
// return {
// "inter": "网络情况",
// "app_channel": "APP渠道",
// "app_version": "APP版本",
// "device_id": "设备ID",
// "source": "来源",
// };
}
/// 获取当前时间戳,单位:秒
static
int
_getDateNow
()
{
int
now
=
(
DateTime
.
now
().
millisecondsSinceEpoch
/
1000
).
floor
();
return
now
;
}
// md5编码
static
String
_md5
(
String
data
)
{
var
bytes
=
utf8
.
encode
(
data
);
var
digest
=
crypto
.
md5
.
convert
(
bytes
);
return
digest
.
toString
();
}
}
}
}
lib/src/tj/exposure.dart
0 → 100644
View file @
5506a457
import
'dart:convert'
;
import
'../db.dart'
;
import
'../utils.dart'
;
class
Exposure
{
DB
_db
;
Exposure
(
DB
db
)
{
_db
=
db
;
}
/// 曝光
void
onExposure
(
{
String
pageId
,
String
exposureId
,
Map
<
String
,
dynamic
>
extras
})
async
{
int
exposureTime
=
Utils
.
getDateNow
();
String
extrasStr
=
json
.
encode
(
extras
);
String
id
=
Utils
.
md5
(
"
${pageId}
_
${exposureId}
_
${extrasStr}
_
$exposureTime
"
);
Map
<
String
,
dynamic
>
map
=
{
"id"
:
id
,
"page_id"
:
pageId
,
"exposure_id"
:
exposureId
,
"exposure_time"
:
exposureTime
,
"extras"
:
extrasStr
,
};
await
_db
.
ready
;
Utils
.
log
(
"exposure"
,
map
);
await
_db
.
db
.
insert
(
"exposure_tj"
,
map
);
}
// 上传数据至接口
void
upload
()
async
{
await
_db
.
ready
;
List
<
Map
>
list
=
await
_db
.
db
.
query
(
"exposure_tj"
,
limit:
100
,
offset:
0
);
if
(
list
.
length
==
0
)
{
return
;
}
String
deviceId
=
await
Utils
.
getDeviceId
();
bool
result
=
await
Utils
.
uploadData
({
"device_id"
:
deviceId
,
"projects"
:
[
{
"event_name"
:
"elem_exposure"
,
"event_data"
:
list
}
]
});
if
(
result
)
{
List
<
String
>
ids
=
list
.
map
((
e
)
=>
e
[
'id'
]).
toList
();
await
_db
.
db
.
rawDelete
(
"delete from exposure_tj where id in('
${ids.join("','")}
')"
);
}
if
(
Utils
.
isDebug
)
{
Utils
.
log
(
"exposure_tj upload_result"
,
{
"ok"
:
result
,
"length"
:
list
.
length
});
}
if
(
list
.
length
==
100
)
{
upload
();
}
}
}
lib/src/tj/tap.dart
0 → 100644
View file @
5506a457
import
'dart:convert'
;
import
'../../src/db.dart'
;
import
'../../src/utils.dart'
;
class
Tap
{
DB
_db
;
Tap
(
DB
db
)
{
_db
=
db
;
}
/// 点击
void
onTap
(
{
String
pageId
,
String
clickId
,
Map
<
String
,
dynamic
>
extras
})
async
{
int
clickTime
=
Utils
.
getDateNow
();
String
extrasStr
=
json
.
encode
(
extras
);
String
id
=
Utils
.
md5
(
"
${pageId}
_
${clickId}
_
${extrasStr}
_
$clickTime
"
);
Map
<
String
,
dynamic
>
map
=
{
"id"
:
id
,
"page_id"
:
pageId
,
"click_id"
:
clickId
,
"click_time"
:
clickTime
,
"extras"
:
extrasStr
,
};
Map
<
String
,
dynamic
>
common
=
await
Utils
.
getCommonParams
();
map
.
addAll
(
common
);
await
_db
.
ready
;
Utils
.
log
(
"tap"
,
map
);
await
_db
.
db
.
insert
(
"tap_tj"
,
map
);
}
// 上传数据至接口
void
upload
()
async
{
await
_db
.
ready
;
List
<
Map
>
list
=
await
_db
.
db
.
query
(
"tap_tj"
,
limit:
100
,
offset:
0
);
if
(
list
.
length
==
0
)
{
return
;
}
String
deviceId
=
await
Utils
.
getDeviceId
();
bool
result
=
await
Utils
.
uploadData
({
"device_id"
:
deviceId
,
"projects"
:
[
{
"event_name"
:
"elem_click"
,
"event_data"
:
list
}
]
});
if
(
result
)
{
List
<
String
>
ids
=
list
.
map
((
e
)
=>
e
[
'id'
]).
toList
();
await
_db
.
db
.
rawDelete
(
"delete from tap_tj where id in('
${ids.join("','")}
')"
);
}
if
(
Utils
.
isDebug
)
{
Utils
.
log
(
"tap_tj upload_result"
,
{
"ok"
:
result
,
"length"
:
list
.
length
});
}
if
(
list
.
length
==
100
)
{
upload
();
}
}
}
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