<commit_before>﻿using System;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using Ruzzie.SensorData.Web.GetData;

namespace Ruzzie.SensorData.Web.Controllers
{
    public class GetDataController : ApiController
    {
        //todo:add ioc
        private static readonly IGetDataService GetDataService = Container.GetDataService;

        /// <summary>
        ///     Reads the latest data entry for a thing.
        /// </summary>
        /// <param name="thing">A unique name of a thing.</param>
        /// <returns><see cref="GetDataResult"/></returns>
        [Route("get/latest/data/for/{thing}")]
        public async Task<GetDataResult> GetLatest(string thing)
        {
            return await GetDataService.GetLastestDataEntryForThingAsync(thing);
        }

        /// <summary>
        ///     Reads the single value for the latest entry for a thing.
        /// </summary>
        /// <remarks> Use this if you do not want or cannot parse to get json.</remarks>
        /// <param name="thing">A unique name of a thing.</param>
        /// <param name="valueName">The name of the value stored in the content data to return.</param>
        /// <response code="404">Thing was not found or no thing name provided.</response>        
        /// <returns><see cref="GetDataResult"/></returns>
        [Route("get/latest/singlevalue/for/{thing}/{valueName}")]
        public async Task<HttpResponseMessage> GetLatestSingleValue(string thing,string valueName)
        {            
            return await Task.Run(async () =>
            {
                var response = new HttpResponseMessage(HttpStatusCode.OK);

                GetDataResult getDataResult = await GetDataService.GetLastestDataEntryForThingAsync(thing);
                switch (getDataResult.GetDataResultCode)
                {
                    case GetDataResultCode.Success:
                        response.Content = new StringContent(getDataResult.ResultData[valueName].ToString(),Encoding.UTF8); 
                        response.StatusCode = HttpStatusCode.OK;
                        break;
                    case GetDataResultCode.FailedNoThingNameProvided:
                        response.StatusCode = HttpStatusCode.NotFound;                        
                        break;
                    case GetDataResultCode.FailedThingNotFound:
                        response.StatusCode = HttpStatusCode.NotFound;                          
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }

                return response;
            });
        }

       

    }
}<commit_msg>fixed typo in comments<commit_after>﻿using System;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using Ruzzie.SensorData.Web.GetData;

namespace Ruzzie.SensorData.Web.Controllers
{
    public class GetDataController : ApiController
    {
        //todo:add ioc
        private static readonly IGetDataService GetDataService = Container.GetDataService;

        /// <summary>
        ///     Reads the latest data entry for a thing.
        /// </summary>
        /// <param name="thing">A unique name of a thing.</param>
        /// <returns><see cref="GetDataResult"/></returns>
        [Route("get/latest/data/for/{thing}")]
        public async Task<GetDataResult> GetLatest(string thing)
        {
            return await GetDataService.GetLastestDataEntryForThingAsync(thing);
        }

        /// <summary>
        ///     Reads the single value for the latest entry for a thing.
        /// </summary>
        /// <remarks> Use this if you do not want or cannot parse json. This returns plain text.</remarks>
        /// <param name="thing">A unique name of a thing.</param>
        /// <param name="valueName">The name of the value stored in the content data to return.</param>
        /// <response code="404">Thing was not found or no thing name provided.</response>        
        /// <returns><see cref="GetDataResult"/></returns>
        [Route("get/latest/singlevalue/for/{thing}/{valueName}")]
        public async Task<HttpResponseMessage> GetLatestSingleValue(string thing,string valueName)
        {            
            return await Task.Run(async () =>
            {
                var response = new HttpResponseMessage(HttpStatusCode.OK);

                GetDataResult getDataResult = await GetDataService.GetLastestDataEntryForThingAsync(thing);
                switch (getDataResult.GetDataResultCode)
                {
                    case GetDataResultCode.Success:
                        response.Content = new StringContent(getDataResult.ResultData[valueName].ToString(),Encoding.UTF8); 
                        response.StatusCode = HttpStatusCode.OK;
                        break;
                    case GetDataResultCode.FailedNoThingNameProvided:
                        response.StatusCode = HttpStatusCode.NotFound;                        
                        break;
                    case GetDataResultCode.FailedThingNotFound:
                        response.StatusCode = HttpStatusCode.NotFound;                          
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }

                return response;
            });
        }

       

    }
}
{'fraction_non_alphanumeric': 0.09414112098675857, 'fraction_numerical': 0.0014511155450752766, 'mean_word_length': 1.7473841554559044, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 49, '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': '7061736', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1312, 'n_words': 325}