forked from mkoloberdin/waze
-
Notifications
You must be signed in to change notification settings - Fork 0
/
roadmap_analytics.c
171 lines (142 loc) · 5.45 KB
/
roadmap_analytics.c
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
/* roadmap_analytics.c
*
* LICENSE:
*
* Copyright 2010 Avi R.
*
* RoadMap is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License V2 as published by
* the Free Software Foundation.
*
* RoadMap is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RoadMap; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "roadmap.h"
#include "roadmap_analytics.h"
#include "roadmap_hash.h"
#include "Realtime/Realtime.h"
#ifdef FLURRY
extern void roadmap_flurry_log_event (const char *event_name, const char *info_name, const char *info_val);
#endif //FLURRY
#define MAX_STATS 100
typedef struct {
int iNumParams;
const char *szEventName;
const char *szParamName[STATS_MAX_ATTRS];
const char *szParamValue[STATS_MAX_ATTRS];
}StatEntry;
typedef struct {
StatEntry statEntry[MAX_STATS];
int iCount;
} StatsTable;
static StatsTable gStatsTable;
/////////////////////////////////////////////////////////////////////////////////////////////////
void roadmap_analytics_clear(void) {
int i;
for (i= 0; i < gStatsTable.iCount; i++){
int j;
for (j = 0; j<= gStatsTable.statEntry[i].iNumParams; j++ ){
if (gStatsTable.statEntry[i].szParamValue[j])
free((void *)gStatsTable.statEntry[i].szParamValue[j]);
}
}
memset(&gStatsTable, 0, sizeof(gStatsTable));
}
/////////////////////////////////////////////////////////////////////////////////////////////////
int roadmap_analytics_count(void) {
return gStatsTable.iCount;
}
/////////////////////////////////////////////////////////////////////////////////////////////////
BOOL roadmap_analytics_is_empty(void) {
return (gStatsTable.iCount == 0);
}
/////////////////////////////////////////////////////////////////////////////////////////////////
static StatEntry *StatsTable_get_Stat(int index) {
return &gStatsTable.statEntry[index];
}
/////////////////////////////////////////////////////////////////////////////////////////////////
const char *StatsTable_getEventName(int index){
StatEntry *entry = StatsTable_get_Stat(index);
if (entry)
return entry->szEventName;
else
return NULL;
}
/////////////////////////////////////////////////////////////////////////////////////////////////
int StatsTable_getNumParams(int index){
StatEntry *entry = StatsTable_get_Stat(index);
if (entry)
return entry->iNumParams;
else
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////////
const char **StatsTable_getParamNames(int index){
StatEntry *entry = StatsTable_get_Stat(index);
if (entry)
return &entry->szParamName[0];
else
return NULL;
}
/////////////////////////////////////////////////////////////////////////////////////////////////
const char **StatsTable_getParamValues(int index){
StatEntry *entry = StatsTable_get_Stat(index);
if (entry)
return &entry->szParamValue[0];
else
return NULL;
}
/////////////////////////////////////////////////////////////////////////////////////////////////
static void StatsTable_AddStat(const char *EventNamme, int iNumParams, const char *ParamName[], const char*ParamValue[]) {
if (roadmap_analytics_count() < MAX_STATS){
int i;
roadmap_log(ROADMAP_DEBUG,"STAT %s %s,%s\n", EventNamme, ParamName[0], ParamValue[0] );
if (iNumParams > STATS_MAX_ATTRS)
iNumParams = STATS_MAX_ATTRS;
gStatsTable.statEntry[roadmap_analytics_count()].iNumParams = iNumParams;
gStatsTable.statEntry[roadmap_analytics_count()].szEventName = EventNamme;
for (i = 0; i < iNumParams; i++){
gStatsTable.statEntry[roadmap_analytics_count()].szParamName[i] = ParamName[i];
if (ParamValue[i])
gStatsTable.statEntry[roadmap_analytics_count()].szParamValue[i] = strdup(ParamValue[i]);
else
gStatsTable.statEntry[roadmap_analytics_count()].szParamValue[i] = NULL;
}
gStatsTable.iCount++;
}else{
// Table is Full. Send List to the server.
roadmap_log(ROADMAP_ERROR, "StatsTable_AddStat list is full ");
Realtime_SendAllStats(NULL);
}
}
//////////////////////////////////////////////////////////////////
void roadmap_analytics_init(void){
roadmap_analytics_clear();
}
void roadmap_analytics_term(void){
if (!roadmap_analytics_is_empty())
Realtime_SendAllStats(NULL);
}
//////////////////////////////////////////////////////////////////
void roadmap_analytics_log_event (const char *event_name, const char *info_name, const char *info_val) {
roadmap_log (ROADMAP_DEBUG, "STAT %s %s,%s", event_name, info_name, info_val );
StatsTable_AddStat(event_name, 1, &info_name, &info_val);
#ifdef FLURRY
roadmap_flurry_log_event (event_name, info_name, info_val);
#endif
}
//////////////////////////////////////////////////////////////////
void roadmap_analytics_log_int_event (const char *event_name, const char *info_name, int info_val) {
char temp[20];
snprintf(temp, 20, "%d", info_val);
roadmap_analytics_log_event(event_name, info_name, (const char *)&temp);
}