import {projectStatsToPredictedSeries} from 'sentry/views/settings/project/server-side-sampling/utils/projectStatsToPredictedSeries';

import {outcomesWithoutClientDiscarded} from '../testUtils';

describe('projectStatsToPredictedSeries', function () {
  it('returns correct series', function () {
    expect(
      projectStatsToPredictedSeries(TestStubs.OutcomesWithReason(), 0.3, 0.1)
    ).toEqual([
      {
        seriesName: 'Indexed and Processed',
        color: '#2BA185',
        barMinHeight: 0,
        type: 'bar',
        stack: 'predictedUsage',
        data: [
          {name: 1656788400000, value: 29437},
          {name: 1656792000000, value: 28213},
          {name: 1656795600000, value: 26325},
          {name: 1656799200000, value: 25982},
          {name: 1656802800000, value: 24720},
          {name: 1656806400000, value: 27873},
          {name: 1656810000000, value: 29096},
          {name: 1656813600000, value: 24303},
          {name: 1656817200000, value: 24337},
          {name: 1656820800000, value: 24941},
          {name: 1656824400000, value: 25125},
          {name: 1656828000000, value: 26933},
          {name: 1656831600000, value: 29639},
          {name: 1656835200000, value: 30842},
          {name: 1656838800000, value: 30289},
          {name: 1656842400000, value: 30219},
          {name: 1656846000000, value: 31726},
          {name: 1656849600000, value: 33460},
          {name: 1656853200000, value: 33654},
          {name: 1656856800000, value: 33003},
          {name: 1656860400000, value: 32401},
          {name: 1656864000000, value: 31969},
          {name: 1656867600000, value: 31281},
          {name: 1656871200000, value: 30730},
          {name: 1656874800000, value: 30192},
          {name: 1656878400000, value: 29997},
          {name: 1656882000000, value: 27718},
          {name: 1656885600000, value: 27479},
          {name: 1656889200000, value: 29928},
          {name: 1656892800000, value: 36845},
          {name: 1656896400000, value: 44476},
          {name: 1656900000000, value: 42343},
          {name: 1656903600000, value: 41643},
          {name: 1656907200000, value: 46482},
          {name: 1656910800000, value: 52756},
          {name: 1656914400000, value: 71796},
          {name: 1656918000000, value: 86751},
          {name: 1656921600000, value: 94012},
          {name: 1656925200000, value: 90893},
          {name: 1656928800000, value: 81914},
          {name: 1656932400000, value: 79947},
          {name: 1656936000000, value: 85457},
          {name: 1656939600000, value: 86994},
          {name: 1656943200000, value: 84871},
          {name: 1656946800000, value: 75413},
          {name: 1656950400000, value: 64979},
          {name: 1656954000000, value: 54560},
          {name: 1656957600000, value: 31291},
        ],
      },
      {
        seriesName: 'Processed',
        color: '#F5B000',
        data: [
          {name: 1656788400000, value: 58873},
          {name: 1656792000000, value: 56426},
          {name: 1656795600000, value: 52650},
          {name: 1656799200000, value: 51965},
          {name: 1656802800000, value: 49439},
          {name: 1656806400000, value: 55747},
          {name: 1656810000000, value: 58193},
          {name: 1656813600000, value: 48605},
          {name: 1656817200000, value: 48675},
          {name: 1656820800000, value: 49882},
          {name: 1656824400000, value: 50249},
          {name: 1656828000000, value: 53866},
          {name: 1656831600000, value: 59278},
          {name: 1656835200000, value: 61684},
          {name: 1656838800000, value: 60578},
          {name: 1656842400000, value: 60438},
          {name: 1656846000000, value: 63451},
          {name: 1656849600000, value: 66920},
          {name: 1656853200000, value: 67308},
          {name: 1656856800000, value: 66005},
          {name: 1656860400000, value: 64802},
          {name: 1656864000000, value: 63939},
          {name: 1656867600000, value: 62562},
          {name: 1656871200000, value: 61460},
          {name: 1656874800000, value: 60385},
          {name: 1656878400000, value: 59994},
          {name: 1656882000000, value: 55435},
          {name: 1656885600000, value: 54958},
          {name: 1656889200000, value: 59857},
          {name: 1656892800000, value: 73690},
          {name: 1656896400000, value: 88951},
          {name: 1656900000000, value: 84686},
          {name: 1656903600000, value: 83286},
          {name: 1656907200000, value: 92963},
          {name: 1656910800000, value: 105512},
          {name: 1656914400000, value: 143592},
          {name: 1656918000000, value: 173502},
          {name: 1656921600000, value: 188025},
          {name: 1656925200000, value: 181787},
          {name: 1656928800000, value: 163829},
          {name: 1656932400000, value: 159894},
          {name: 1656936000000, value: 170915},
          {name: 1656939600000, value: 173987},
          {name: 1656943200000, value: 169742},
          {name: 1656946800000, value: 150827},
          {name: 1656950400000, value: 129958},
          {name: 1656954000000, value: 109120},
          {name: 1656957600000, value: 62582},
        ],
        barMinHeight: 0,
        type: 'bar',
        stack: 'predictedUsage',
      },
      {
        seriesName: 'Discarded',
        color: '#F55459',
        data: [
          {name: 1656788400000, value: 206056},
          {name: 1656792000000, value: 197490},
          {name: 1656795600000, value: 184274},
          {name: 1656799200000, value: 181876},
          {name: 1656802800000, value: 173037},
          {name: 1656806400000, value: 195114},
          {name: 1656810000000, value: 203674},
          {name: 1656813600000, value: 170118},
          {name: 1656817200000, value: 170361},
          {name: 1656820800000, value: 174586},
          {name: 1656824400000, value: 175873},
          {name: 1656828000000, value: 188531},
          {name: 1656831600000, value: 207472},
          {name: 1656835200000, value: 215894},
          {name: 1656838800000, value: 212022},
          {name: 1656842400000, value: 211532},
          {name: 1656846000000, value: 222079},
          {name: 1656849600000, value: 234219},
          {name: 1656853200000, value: 235579},
          {name: 1656856800000, value: 231019},
          {name: 1656860400000, value: 226806},
          {name: 1656864000000, value: 223786},
          {name: 1656867600000, value: 218968},
          {name: 1656871200000, value: 215110},
          {name: 1656874800000, value: 211346},
          {name: 1656878400000, value: 209980},
          {name: 1656882000000, value: 194023},
          {name: 1656885600000, value: 192352},
          {name: 1656889200000, value: 209499},
          {name: 1656892800000, value: 257914},
          {name: 1656896400000, value: 311329},
          {name: 1656900000000, value: 296402},
          {name: 1656903600000, value: 291501},
          {name: 1656907200000, value: 325371},
          {name: 1656910800000, value: 369291},
          {name: 1656914400000, value: 502573},
          {name: 1656918000000, value: 607258},
          {name: 1656921600000, value: 658087},
          {name: 1656925200000, value: 636254},
          {name: 1656928800000, value: 573400},
          {name: 1656932400000, value: 559630},
          {name: 1656936000000, value: 598202},
          {name: 1656939600000, value: 608956},
          {name: 1656943200000, value: 594097},
          {name: 1656946800000, value: 527893},
          {name: 1656950400000, value: 454853},
          {name: 1656954000000, value: 381921},
          {name: 1656957600000, value: 219036},
        ],
        barMinHeight: 0,
        type: 'bar',
        stack: 'predictedUsage',
      },
    ]);
  });

  it('handles outcomes without client reports', function () {
    expect(
      projectStatsToPredictedSeries(outcomesWithoutClientDiscarded, 0.3, 0.1, 0.2)
    ).toEqual([
      {
        seriesName: 'Indexed and Processed',
        color: '#2BA185',
        barMinHeight: 0,
        type: 'bar',
        stack: 'predictedUsage',
        data: [
          {name: 1656788400000, value: 147183},
          {name: 1656792000000, value: 141064},
          {name: 1656795600000, value: 131624},
          {name: 1656799200000, value: 129911},
          {name: 1656802800000, value: 123551},
          {name: 1656806400000, value: 139367},
          {name: 1656810000000, value: 145481},
          {name: 1656813600000, value: 121513},
          {name: 1656817200000, value: 121404},
          {name: 1656820800000, value: 124615},
          {name: 1656824400000, value: 125623},
          {name: 1656828000000, value: 134665},
          {name: 1656831600000, value: 148194},
          {name: 1656835200000, value: 154210},
          {name: 1656838800000, value: 151334},
          {name: 1656842400000, value: 151092},
          {name: 1656846000000, value: 158485},
          {name: 1656849600000, value: 167067},
          {name: 1656853200000, value: 168229},
          {name: 1656856800000, value: 165010},
          {name: 1656860400000, value: 162004},
          {name: 1656864000000, value: 158930},
          {name: 1656867600000, value: 156334},
          {name: 1656871200000, value: 153650},
          {name: 1656874800000, value: 150962},
          {name: 1656878400000, value: 149985},
          {name: 1656882000000, value: 138588},
          {name: 1656885600000, value: 137394},
          {name: 1656889200000, value: 149642},
          {name: 1656892800000, value: 184224},
          {name: 1656896400000, value: 222378},
          {name: 1656900000000, value: 211715},
          {name: 1656903600000, value: 208215},
          {name: 1656907200000, value: 232407},
          {name: 1656910800000, value: 263355},
          {name: 1656914400000, value: 346316},
          {name: 1656918000000, value: 360156},
          {name: 1656921600000, value: 360055},
          {name: 1656925200000, value: 359967},
          {name: 1656928800000, value: 359777},
          {name: 1656932400000, value: 359092},
          {name: 1656936000000, value: 360026},
          {name: 1656939600000, value: 359224},
          {name: 1656943200000, value: 360063},
          {name: 1656946800000, value: 356245},
          {name: 1656950400000, value: 321693},
          {name: 1656954000000, value: 272728},
          {name: 1656957600000, value: 155764},
        ],
      },
      {
        seriesName: 'Processed',
        color: '#F5B000',
        data: [
          {name: 1656788400000, value: 294365},
          {name: 1656792000000, value: 282128},
          {name: 1656795600000, value: 263247},
          {name: 1656799200000, value: 259822},
          {name: 1656802800000, value: 247101},
          {name: 1656806400000, value: 278733},
          {name: 1656810000000, value: 290962},
          {name: 1656813600000, value: 243026},
          {name: 1656817200000, value: 242807},
          {name: 1656820800000, value: 249230},
          {name: 1656824400000, value: 251246},
          {name: 1656828000000, value: 269329},
          {name: 1656831600000, value: 296387},
          {name: 1656835200000, value: 308420},
          {name: 1656838800000, value: 302667},
          {name: 1656842400000, value: 302183},
          {name: 1656846000000, value: 316969},
          {name: 1656849600000, value: 334134},
          {name: 1656853200000, value: 336458},
          {name: 1656856800000, value: 330020},
          {name: 1656860400000, value: 324008},
          {name: 1656864000000, value: 317859},
          {name: 1656867600000, value: 312667},
          {name: 1656871200000, value: 307300},
          {name: 1656874800000, value: 301923},
          {name: 1656878400000, value: 299970},
          {name: 1656882000000, value: 277175},
          {name: 1656885600000, value: 274788},
          {name: 1656889200000, value: 299284},
          {name: 1656892800000, value: 368447},
          {name: 1656896400000, value: 444755},
          {name: 1656900000000, value: 423429},
          {name: 1656903600000, value: 416430},
          {name: 1656907200000, value: 464814},
          {name: 1656910800000, value: 526710},
          {name: 1656914400000, value: 692631},
          {name: 1656918000000, value: 720312},
          {name: 1656921600000, value: 720110},
          {name: 1656925200000, value: 719933},
          {name: 1656928800000, value: 719553},
          {name: 1656932400000, value: 718183},
          {name: 1656936000000, value: 720052},
          {name: 1656939600000, value: 718448},
          {name: 1656943200000, value: 720125},
          {name: 1656946800000, value: 712490},
          {name: 1656950400000, value: 643386},
          {name: 1656954000000, value: 545456},
          {name: 1656957600000, value: 311527},
        ],
        barMinHeight: 0,
        type: 'bar',
        stack: 'predictedUsage',
      },
      {
        seriesName: 'Discarded',
        color: '#F55459',
        data: [
          {name: 1656788400000, value: 1030278},
          {name: 1656792000000, value: 987448},
          {name: 1656795600000, value: 921365},
          {name: 1656799200000, value: 909377},
          {name: 1656802800000, value: 864854},
          {name: 1656806400000, value: 975566},
          {name: 1656810000000, value: 1018367},
          {name: 1656813600000, value: 850591},
          {name: 1656817200000, value: 849825},
          {name: 1656820800000, value: 872305},
          {name: 1656824400000, value: 879361},
          {name: 1656828000000, value: 942652},
          {name: 1656831600000, value: 1037355},
          {name: 1656835200000, value: 1079470},
          {name: 1656838800000, value: 1059335},
          {name: 1656842400000, value: 1057641},
          {name: 1656846000000, value: 1109392},
          {name: 1656849600000, value: 1169469},
          {name: 1656853200000, value: 1177603},
          {name: 1656856800000, value: 1155070},
          {name: 1656860400000, value: 1134028},
          {name: 1656864000000, value: 1112507},
          {name: 1656867600000, value: 1094335},
          {name: 1656871200000, value: 1075550},
          {name: 1656874800000, value: 1056731},
          {name: 1656878400000, value: 1049895},
          {name: 1656882000000, value: 970113},
          {name: 1656885600000, value: 961758},
          {name: 1656889200000, value: 1047494},
          {name: 1656892800000, value: 1289565},
          {name: 1656896400000, value: 1556643},
          {name: 1656900000000, value: 1482002},
          {name: 1656903600000, value: 1457505},
          {name: 1656907200000, value: 1626849},
          {name: 1656910800000, value: 1843485},
          {name: 1656914400000, value: 2424209},
          {name: 1656918000000, value: 2521092},
          {name: 1656921600000, value: 2520385},
          {name: 1656925200000, value: 2519766},
          {name: 1656928800000, value: 2518436},
          {name: 1656932400000, value: 2513641},
          {name: 1656936000000, value: 2520182},
          {name: 1656939600000, value: 2514568},
          {name: 1656943200000, value: 2520438},
          {name: 1656946800000, value: 2493715},
          {name: 1656950400000, value: 2251851},
          {name: 1656954000000, value: 1909096},
          {name: 1656957600000, value: 1090345},
        ],
        barMinHeight: 0,
        type: 'bar',
        stack: 'predictedUsage',
      },
    ]);
  });
});
