/// <summary> /// Enum to text /// </summary> /// <param name="type"></param> /// <returns></returns> public static string ToText(StatsType.Enum type) { return(type switch { StatsType.Enum.Tested => StatsType.Tested, StatsType.Enum.EHealthNotification => StatsType.EHealthNotification, StatsType.Enum.Notification => StatsType.Notification, StatsType.Enum.Repeat => StatsType.Repeat, StatsType.Enum.Positive => StatsType.Positive, StatsType.Enum.Negative => StatsType.Negative, StatsType.Enum.RegisteredTo => StatsType.RegisteredTo, StatsType.Enum.RegisteredOn => StatsType.RegisteredOn, _ => throw new Exception("Invalid slot type"), });
/// <summary> /// DecrementStats /// </summary> /// <param name="statsType">Model.StatsType.*</param> /// <param name="slotType"></param> /// <param name="slotId"></param> /// <param name="placeId"></param> /// <returns></returns> public virtual async Task <long?> GetStats(StatsType.Enum statsType, SlotType.Enum slotType, string placeId, long slotId) { var time = new DateTimeOffset(slotId, TimeSpan.Zero); var t = slotType switch { SlotType.Enum.Day => time.RoundDay(), SlotType.Enum.Hour => time.RoundHour(), SlotType.Enum.Min => time.RoundMinute(), _ => throw new Exception("Invalid slot type"), };/**/ var keyPlace = $"{StatsType.ToText(statsType)}-slot-{SlotType.ToText(slotType)}-{placeId}-{t}"; return(await redisCacheClient.Db0.HashGetAsync <long?>( $"{configuration["db-prefix"]}{REDIS_KEY_SLOT_STATS}", keyPlace )); }
/// <summary> /// DecrementStats /// </summary> /// <param name="statsType">Model.StatsType.*</param> /// <param name="slotType"></param> /// <param name="time"></param> /// <param name="placeId"></param> /// <returns></returns> public virtual async Task <long> DecrementStats(StatsType.Enum statsType, SlotType.Enum slotType, string placeId, DateTimeOffset time) { var t = slotType switch { SlotType.Enum.Day => time.RoundDay(), SlotType.Enum.Hour => time.RoundHour(), SlotType.Enum.Min => time.RoundMinute(), _ => throw new Exception("Invalid slot type"), }; var keyPlace = $"{StatsType.ToText(statsType)}-slot-{SlotType.ToText(slotType)}-{placeId}-{t}"; return(await redisCacheClient.Db0.HashIncerementByAsync( $"{configuration["db-prefix"]}{REDIS_KEY_SLOT_STATS}", keyPlace, -1 )); }
/// <summary> /// Return stats for specific place and time /// </summary> /// <param name="statsType"></param> /// <param name="slotType"></param> /// <param name="placeId"></param> /// <param name="slotId"></param> /// <returns></returns> public async override Task <long?> GetStats(StatsType.Enum statsType, SlotType.Enum slotType, string placeId, long slotId) { var time = new DateTimeOffset(slotId, TimeSpan.Zero); var t = slotType switch { SlotType.Enum.Day => time.RoundDay(), SlotType.Enum.Hour => time.RoundHour(), SlotType.Enum.Min => time.RoundMinute(), _ => throw new Exception("Invalid slot type"), };/**/ var keyPlace = $"{StatsType.ToText(statsType)}-slot-{SlotType.ToText(slotType)}-{placeId}-{t}"; if (Stats.ContainsKey(keyPlace)) { return(Stats[keyPlace]); } return(0); }
/// <summary> /// Decrement stats /// </summary> /// <param name="statsType"></param> /// <param name="slotType"></param> /// <param name="placeId"></param> /// <param name="time"></param> /// <returns></returns> public async override Task <long> DecrementStats(StatsType.Enum statsType, SlotType.Enum slotType, string placeId, DateTimeOffset time) { var t = slotType switch { SlotType.Enum.Day => time.RoundDay(), SlotType.Enum.Hour => time.RoundHour(), SlotType.Enum.Min => time.RoundMinute(), _ => throw new Exception("Invalid slot type"), }; var keyPlace = $"{StatsType.ToText(statsType)}-slot-{SlotType.ToText(slotType)}-{placeId}-{t}"; if (!Stats.ContainsKey(keyPlace)) { Stats[keyPlace] = 0; } Stats[keyPlace]--; return(Stats[keyPlace]); }