<commit_before>﻿using System;
using System.Web.Http;
using DataService.Models;

namespace DataService.Controllers
{
    [RoutePrefix("shcomp")]
    public class ShanghaiCompositeIndexController : ApiController
    {
        private const double BaseIndex = 5000.0;
        private const int ChangeLimitationInPercentage = 3;

        [HttpGet]
        [Route("")]
        public Index RandomIndex()
        {
            return RandomIndex(BaseIndex);
        }

        [HttpGet]
        [Route("last/{lastIndex}")]
        public Index RandomIndex(double lastIndex)
        {
            var random = new Random();
            var up = random.NextDouble() < 0.5 ? -1 : 1;
            var randomChangedPercent = random.Next(ChangeLimitationInPercentage * 100) / 100.0;
            var change = BaseIndex*(randomChangedPercent/100);

            var indexValue = BaseIndex + change * up;
            var timestamp = DateTime.Now.ToString("HH:mm:ss");

            return new Index {Time = timestamp, Value = indexValue};
        }<commit_msg>Can return random X indicies<commit_after>﻿using System;
using System.Collections.Generic;
using System.Web.Http;
using DataService.Models;

namespace DataService.Controllers
{
    [RoutePrefix("shcomp")]
    public class ShanghaiCompositeIndexController : ApiController
    {
        private const double BaseIndexValue = 5000.0;
        private const int ChangeLimitationInPercentage = 3;

        [HttpGet]
        [Route("")]
        public Index RandomIndex()
        {
            return RandomIndex(BaseIndexValue);
        }

        [HttpGet]
        [Route("multi/{count}")]
        public IList<Index> RandomMultiIndices(double count)
        {
            DateTime now = DateTime.Now;

            var indices = new List<Index> {BuildIndex(now.AddSeconds((count - 1) * -1), RandomIndexValue(BaseIndexValue))};
            for (int i = indices.Count; i < count; i++)
            {
                var lastIndex = indices[indices.Count - 1];
                indices.Add(BuildIndex(now.AddSeconds((count - 1 - i) * -1), RandomIndexValue(lastIndex.Value)));
            }
            return indices;
        }

        [HttpGet]
        [Route("last/{lastIndex}")]
        public Index RandomIndex(double lastIndex)
        {
            return BuildIndex(DateTime.Now, RandomIndexValue(lastIndex));
        }

        private Index BuildIndex(DateTime timestamp, double value)
        {
            return new Index { Time = timestamp.ToString("HH:mm:ss"), Value = value };
        }

        private double RandomIndexValue(double lastIndex)
        {
            var random = new Random(Guid.NewGuid().GetHashCode());
            var up = random.NextDouble() < 0.5 ? -1 : 1;
            double randomChangedPercent = random.Next(ChangeLimitationInPercentage * 100) / 100.0;
            double change = lastIndex * (randomChangedPercent / 100);

            return Retain2Digits(lastIndex + change * up);
        }

        private double Retain2Digits(double value)
        {
            return ((int)(value * 100)) / 100.0;
        }
{'fraction_non_alphanumeric': 0.10333657272432782, 'fraction_numerical': 0.01749271137026239, 'mean_word_length': 2.183505154639175, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2405935', 'n_tokens_mistral': 852, 'n_tokens_neox': 801, 'n_words': 198}