PlayerStats.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. // <copyright file="PlayerStats.cs" company="Google Inc.">
  2. // Copyright (C) 2015 Google Inc.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. // </copyright>
  16. #if UNITY_ANDROID
  17. namespace GooglePlayGames.BasicApi
  18. {
  19. using System;
  20. /// <summary>
  21. /// Player stats. See https://developers.google.com/games/services/android/stats
  22. /// </summary>
  23. public class PlayerStats
  24. {
  25. private static float UNSET_VALUE = -1.0f;
  26. public PlayerStats(
  27. int numberOfPurchases,
  28. float avgSessionLength,
  29. int daysSinceLastPlayed,
  30. int numberOfSessions,
  31. float sessPercentile,
  32. float spendPercentile,
  33. float spendProbability,
  34. float churnProbability,
  35. float highSpenderProbability,
  36. float totalSpendNext28Days)
  37. {
  38. mValid = true;
  39. mNumberOfPurchases = numberOfPurchases;
  40. mAvgSessionLength = avgSessionLength;
  41. mDaysSinceLastPlayed = daysSinceLastPlayed;
  42. mNumberOfSessions = numberOfSessions;
  43. mSessPercentile = sessPercentile;
  44. mSpendPercentile = spendPercentile;
  45. mSpendProbability = spendProbability;
  46. mChurnProbability = churnProbability;
  47. mHighSpenderProbability = highSpenderProbability;
  48. mTotalSpendNext28Days = totalSpendNext28Days;
  49. }
  50. public PlayerStats()
  51. {
  52. mValid = false;
  53. }
  54. private bool mValid;
  55. private int mNumberOfPurchases;
  56. private float mAvgSessionLength;
  57. private int mDaysSinceLastPlayed;
  58. private int mNumberOfSessions;
  59. private float mSessPercentile;
  60. private float mSpendPercentile;
  61. private float mSpendProbability;
  62. private float mChurnProbability;
  63. private float mHighSpenderProbability;
  64. private float mTotalSpendNext28Days;
  65. /// <summary>
  66. /// If this PlayerStats object is valid (i.e. successfully retrieved from games services).
  67. /// </summary>
  68. /// <remarks>
  69. /// Note that a PlayerStats with all stats unset may still be valid.
  70. /// </remarks>
  71. public bool Valid
  72. {
  73. get { return mValid; }
  74. }
  75. /// <summary>
  76. /// The number of in-app purchases.
  77. /// </summary>
  78. public int NumberOfPurchases
  79. {
  80. get { return mNumberOfPurchases; }
  81. }
  82. /// <summary>
  83. /// The length of the avg session in minutes.
  84. /// </summary>
  85. public float AvgSessionLength
  86. {
  87. get { return mAvgSessionLength; }
  88. }
  89. /// <summary>
  90. /// The days since last played.
  91. /// </summary>
  92. public int DaysSinceLastPlayed
  93. {
  94. get { return mDaysSinceLastPlayed; }
  95. }
  96. /// <summary>
  97. /// The number of sessions based on sign-ins.
  98. /// </summary>
  99. public int NumberOfSessions
  100. {
  101. get { return mNumberOfSessions; }
  102. }
  103. /// <summary>
  104. /// The approximation of sessions percentile for the player.
  105. /// </summary>
  106. /// <remarks>
  107. /// This value is given as a decimal value between 0 and 1 (inclusive).
  108. /// It indicates how many sessions the current player has
  109. /// played in comparison to the rest of this game's player base.
  110. /// Higher numbers indicate that this player has played more sessions.
  111. /// A return value less than zero indicates this value is not available.
  112. /// </remarks>
  113. public float SessPercentile
  114. {
  115. get { return mSessPercentile; }
  116. }
  117. /// <summary>
  118. /// The approximate spend percentile of the player.
  119. /// </summary>
  120. /// <remarks>
  121. /// This value is given as a decimal value between 0 and 1 (inclusive).
  122. /// It indicates how much the current player has spent in
  123. /// comparison to the rest of this game's player base. Higher
  124. /// numbers indicate that this player has spent more.
  125. /// A return value less than zero indicates this value is not available.
  126. /// </remarks>
  127. public float SpendPercentile
  128. {
  129. get { return mSpendPercentile; }
  130. }
  131. /// <summary>
  132. /// The approximate probability of the player choosing to spend in this game.
  133. /// </summary>
  134. /// <remarks>
  135. /// This value is given as a decimal value between 0 and 1 (inclusive).
  136. /// Higher values indicate that a player is more likely to spend.
  137. /// A return value less than zero indicates this value is not available.
  138. /// </remarks>
  139. public float SpendProbability
  140. {
  141. get { return mSpendProbability; }
  142. }
  143. /// <summary>
  144. /// The approximate probability of the player not returning to play the game.
  145. /// </summary>
  146. /// <remarks>
  147. /// Higher values indicate that a player is less likely to return.
  148. /// A return value less than zero indicates this value is not available.
  149. /// </remarks>
  150. public float ChurnProbability
  151. {
  152. get { return mChurnProbability; }
  153. }
  154. /// <summary>
  155. /// The high spender probability of this player.
  156. /// </summary>
  157. public float HighSpenderProbability
  158. {
  159. get { return mHighSpenderProbability; }
  160. }
  161. /// <summary>
  162. /// The predicted total spend of this player over the next 28 days.
  163. /// </summary>
  164. public float TotalSpendNext28Days
  165. {
  166. get { return mTotalSpendNext28Days; }
  167. }
  168. /// <summary>
  169. /// Determines whether this instance has NumberOfPurchases.
  170. /// </summary>
  171. /// <returns><c>true</c> if this instance has NumberOfPurchases; otherwise, <c>false</c>.</returns>
  172. public bool HasNumberOfPurchases()
  173. {
  174. return NumberOfPurchases != (int) UNSET_VALUE;
  175. }
  176. /// <summary>
  177. /// Determines whether this instance has AvgSessionLength.
  178. /// </summary>
  179. /// <returns><c>true</c> if this instance has AvgSessionLength; otherwise, <c>false</c>.</returns>
  180. public bool HasAvgSessionLength()
  181. {
  182. return AvgSessionLength != UNSET_VALUE;
  183. }
  184. /// <summary>
  185. /// Determines whether this instance has DaysSinceLastPlayed.
  186. /// </summary>
  187. /// <returns><c>true</c> if this instance has DaysSinceLastPlayed; otherwise, <c>false</c>.</returns>
  188. public bool HasDaysSinceLastPlayed()
  189. {
  190. return DaysSinceLastPlayed != (int) UNSET_VALUE;
  191. }
  192. /// <summary>
  193. /// Determines whether this instance has NumberOfSessions.
  194. /// </summary>
  195. /// <returns><c>true</c> if this instance has NumberOfSessions; otherwise, <c>false</c>.</returns>
  196. public bool HasNumberOfSessions()
  197. {
  198. return NumberOfSessions != (int) UNSET_VALUE;
  199. }
  200. /// <summary>
  201. /// Determines whether this instance has SessPercentile.
  202. /// </summary>
  203. /// <returns><c>true</c> if this instance has SessPercentile; otherwise, <c>false</c>.</returns>
  204. public bool HasSessPercentile()
  205. {
  206. return SessPercentile != UNSET_VALUE;
  207. }
  208. /// <summary>
  209. /// Determines whether this instance has SpendPercentile.
  210. /// </summary>
  211. /// <returns><c>true</c> if this instance has SpendPercentile; otherwise, <c>false</c>.</returns>
  212. public bool HasSpendPercentile()
  213. {
  214. return SpendPercentile != UNSET_VALUE;
  215. }
  216. /// <summary>
  217. /// Determines whether this instance has ChurnProbability.
  218. /// </summary>
  219. /// <returns><c>true</c> if this instance has ChurnProbability; otherwise, <c>false</c>.</returns>
  220. public bool HasChurnProbability()
  221. {
  222. return ChurnProbability != UNSET_VALUE;
  223. }
  224. /// <summary>
  225. /// Determines whether this instance has HighSpenderProbability.
  226. /// </summary>
  227. /// <returns><c>true</c> if this instance has HighSpenderProbability; otherwise, <c>false</c>.</returns>
  228. public bool HasHighSpenderProbability()
  229. {
  230. return HighSpenderProbability != UNSET_VALUE;
  231. }
  232. /// <summary>
  233. /// Determines whether this instance has TotalSpendNext28Days.
  234. /// </summary>
  235. /// <returns><c>true</c> if this instance has TotalSpendNext28Days; otherwise, <c>false</c>.</returns>
  236. public bool HasTotalSpendNext28Days()
  237. {
  238. return TotalSpendNext28Days != UNSET_VALUE;
  239. }
  240. }
  241. }
  242. #endif