Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AnalyticsInteractions.c
Go to the documentation of this file.
1// Class that tracks interactions in server browser, scenarios, and workshop
2// Note: Not all of these section need to have all the exact same sections (e.g., scenarios do not have filters)
4{
5 protected static const int MIN_DELAY_BETWEEN_SEARCHES_MS = 100;
6 protected ref SCR_AnalyticsDelayedSend m_DelayedSend = new SCR_AnalyticsDelayedSend();
11 protected int m_iSearchUsages = 0;
12 protected int m_iFilterOnUsages = 0;
13 protected int m_iFavoriteUsages = 0;
14 protected int m_iReopenTimes = 1;
15 protected bool m_bIsOpened = false;
16
17 //------------------------------------------------------------------------------------------------
20 void Start()
21 {
22 m_bIsOpened = true;
23 m_DelayedSend.Start();
24 if (m_DelayedSend.IsAdditive())
25 {
26 m_iReopenTimes += 1;
27 }
28 else
29 {
30 m_Tabs.Clear();
31 m_Sortings.Clear();
32 m_Filters.Clear();
37 }
38 }
39
40 //------------------------------------------------------------------------------------------------
43 void Close()
44 {
45 m_DelayedSend.Stop();
46 m_bIsOpened = false;
47 }
48
49 //------------------------------------------------------------------------------------------------
52 void Update(float deltaSeconds)
53 {
54 m_DelayedSend.Update(deltaSeconds);
55 }
56
57 //------------------------------------------------------------------------------------------------
61 {
62 return m_DelayedSend.IsReadyToSend();
63 }
64
65 //------------------------------------------------------------------------------------------------
68 {
69 m_DelayedSend.ResetReadyToSend();
70 }
71
72 //------------------------------------------------------------------------------------------------
75 {
76 return m_iReopenTimes;
77 }
78
79 //------------------------------------------------------------------------------------------------
82 {
83 return m_DelayedSend.GetTimeSpent();
84 }
85
86 //------------------------------------------------------------------------------------------------
89 void SetTab(string tab)
90 {
91 if (!m_bIsOpened)
92 return;
93
94 int count = m_Tabs.Get(tab); // Get returns 0 if tab is not used
95 m_Tabs.Set(tab, count + 1);
96 }
97
98 //------------------------------------------------------------------------------------------------
101 void SetSorting(string sorting)
102 {
103 if (!m_bIsOpened)
104 return;
105
106 int count = m_Sortings.Get(sorting); // Get returns 0 if sorting is not used
107 m_Sortings.Set(sorting, count + 1);
108 }
109
110 //------------------------------------------------------------------------------------------------
114 void SetFilter(string filterCategory, string filterName)
115 {
116 if (!m_bIsOpened)
117 return;
118
119 if (!m_Filters.Contains(filterCategory))
120 m_Filters.Insert(filterCategory, new map<string, int>());
121
122 map<string, int> filterNames = m_Filters.Get(filterCategory);
123 int count = filterNames.Get(filterName);
124 filterNames.Set(filterName, count + 1);
125 }
126
127 //------------------------------------------------------------------------------------------------
130 {
131 if (!m_bIsOpened)
132 return;
133
134 // Search box is broken as it sometimes sends two events when confirmed instead of one therefore
135 // we measure how much time has past between them, and if it is short enough we ignore the
136 // second event.
137 WorldTimestamp current = GetGame().GetWorld().GetTimestamp();
138
139 if (m_LastSearchUsage && current.DiffMilliseconds(m_LastSearchUsage) < MIN_DELAY_BETWEEN_SEARCHES_MS)
140 return;
141
142 m_iSearchUsages += 1;
143 m_LastSearchUsage = current;
144 }
145
146 //------------------------------------------------------------------------------------------------
149 {
150 if (!m_bIsOpened)
151 return;
152
154 }
155
156 //------------------------------------------------------------------------------------------------
159 {
160 if (!m_bIsOpened)
161 return;
162
164 }
165
166 //------------------------------------------------------------------------------------------------
170 {
171 array<string> arr = new array<string>();
172
173 if (!m_Tabs.IsEmpty())
174 arr.Insert(string.Format("'TabName':%1", SerializeMap(m_Tabs)));
175
176 if (!m_Sortings.IsEmpty())
177 arr.Insert(string.Format("'Sorting':%1", SerializeMap(m_Sortings)));
178
179 if (!m_Filters.IsEmpty())
180 arr.Insert(string.Format("'Filters':%1", SerializeFilters()));
181
182 if (m_iSearchUsages > 0)
183 arr.Insert(string.Format("'Searches':%1", m_iSearchUsages));
184
185 if (m_iFilterOnUsages > 0)
186 arr.Insert(string.Format("'FilterOn':%1", m_iFilterOnUsages));
187
188 string result = "{";
189 bool firstElement = true;
190 foreach (string val : arr)
191 {
192 if (firstElement)
193 result += val;
194 else
195 result += "," + val;
196
197 firstElement = false;
198 }
199
200 return result + "}";
201 }
202
203 //------------------------------------------------------------------------------------------------
204 protected string SerializeMap(map<string, int> mapp)
205 {
206 string result = "{";
207
208 bool firstElement = true;
209 foreach (string category, int count : mapp)
210 {
211 if (firstElement)
212 result += string.Format("'%1':%2", category, count);
213 else
214 result += string.Format(",'%1':%2", category, count);
215
216 firstElement = false;
217 }
218
219 return result + "}";
220 }
221
222 //------------------------------------------------------------------------------------------------
223 protected string SerializeFilters()
224 {
225 string result = "{";
226
227 bool firstElement = true;
228 foreach (string category, map<string, int> names : m_Filters)
229 {
230 if (firstElement)
231 result += string.Format("'%1':%2", category, SerializeMap(names));
232 else
233 result += string.Format(",'%1':%2", category, SerializeMap(names));
234
235 firstElement = false;
236 }
237
238 return result + "}";
239 }
240}
ArmaReforgerScripted GetGame()
Definition game.c:1398
ref map< string, int > m_Sortings
void UseFilterOn()
Use filter toggle and save it to the interactions.
void ResetReadyToSend()
We sended the data, reset current state.
void Update(float deltaSeconds)
ref map< string, ref map< string, int > > m_Filters
ref SCR_AnalyticsDelayedSend m_DelayedSend
void SetFilter(string filterCategory, string filterName)
string SerializeMap(map< string, int > mapp)
static const int MIN_DELAY_BETWEEN_SEARCHES_MS
void UseSearch()
Use search box and save it to the interactions.
void UseFavorite()
Use favorite button to the interactions.
Definition Types.c:486