Skip to content

Instantly share code, notes, and snippets.

@icebeam7
Last active December 18, 2019 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icebeam7/ea0ffb2d43433557f272930e3875b92c to your computer and use it in GitHub Desktop.
Save icebeam7/ea0ffb2d43433557f272930e3875b92c to your computer and use it in GitHub Desktop.
AnomalyDetector: FileService.cs
using System;
using System.IO;
using System.Reflection;
using System.Collections.Generic;
using AdExchangeAnalyzer.Models;
namespace AdExchangeAnalyzer.Services
{
public static class FileService
{
public static List<DataPoint> ReadFile()
{
var assembly = IntrospectionExtensions.GetTypeInfo(typeof(FileService)).Assembly;
var fullName = $"AdExchangeAnalyzer.Data.data.csv";
var stream = assembly.GetManifestResourceStream(fullName);
var series = new List<DataPoint>();
using (var reader = new StreamReader(stream))
{
var line = string.Empty;
while ((line = reader.ReadLine()) != null)
{
var data = line.Split(',');
if (data.Length == 2)
{
series.Add(new DataPoint()
{
Timestamp = DateTime.Parse(data[0]).ToUniversalTime(),
Value = float.Parse(data[1])
});
}
}
}
return series;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment