SHARE
TWEET

Untitled

a guest Jan 24th, 2020 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Net.Http;
  5. using System.Linq;
  6. namespace PTW_AI
  7. {
  8.     class Program
  9.     {
  10.         static async System.Threading.Tasks.Task Main(string[] args)
  11.         {
  12.             HttpClient httpClient = new HttpClient();
  13.  
  14.             var url = "https://api20200119075613.azurewebsites.net/api/transactions";
  15.             var result = httpClient.GetAsync(url);
  16.             var stringConverted = await result.Result.Content.ReadAsStringAsync();
  17.             var list = JsonConvert.DeserializeObject<List<Transaction>>(stringConverted);
  18.  
  19.             Program p = new Program();
  20.  
  21.             var freqList = p.frequencyPerDay(list,1);
  22.             var vgList = p.calculateVG(freqList);
  23.             var productsSoldList = p.calculateEstimatedProductsSoldPerDay(vgList);
  24.             var a = p.calculateProductRefillDate(productsSoldList, 3, DateTime.Now);
  25.             var abc = "1";
  26.            
  27.         }
  28.  
  29.         public List<int> frequencyPerDay(List<Transaction> transactions, int productId)
  30.         {
  31.             return transactions.Where(_ => _.ProductId == productId).Select(_ => _.Timestamp)
  32.                 .OrderByDescending(_ => _.Date).GroupBy(_ => _).ToDictionary(_ => _.Key, _ => _.Count()).Values.ToList(); ;
  33.         }
  34.  
  35.         public List<int> calculateVG(List<int> list) {
  36.             List<int> result = new List<int>();
  37.             for (int i = 1; i < list.Count() - 1; i++)
  38.             {
  39.                 result.Add(list[i]);
  40.             }
  41.             return result;
  42.         }
  43.  
  44.         public List<int> calculateEstimatedProductsSoldPerDay(List<int> vgList)
  45.         {
  46.             List<int> result = new List<int>();
  47.             foreach (int i in vgList) {
  48.                 int deviation = i - 3;
  49.                 result.Add(i + deviation);
  50.             }
  51.             return result;
  52.         }
  53.  
  54.         public DateTime calculateProductRefillDate(List<int> estimatedProductsSoldPerDayList, int currentStock, DateTime lastRefilledDate)
  55.         {
  56.             int index = 0;
  57.             while (currentStock > 1)
  58.             {
  59.                 currentStock -= estimatedProductsSoldPerDayList[index];
  60.                 index++;
  61.             }
  62.             var x = lastRefilledDate.AddDays(index);
  63.             return lastRefilledDate;
  64.         }
  65.     }
  66. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top