using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using QuantConnect.Lean.Engine.DataFeeds;
namespace QuantConnect.Lean.Engine.Results
{
///
/// Provides base functionality to the implementations of
///
public class BaseResultsHandler
{
protected IDataFeedSubscriptionManager DataManager;
///
/// Gets or sets the current alpha runtime statistics
///
protected AlphaRuntimeStatistics AlphaRuntimeStatistics { get; set; }
///
/// Returns the location of the logs
///
/// Id that will be incorporated into the algorithm log name
/// The logs to save
/// The path to the logs
public virtual string SaveLogs(string id, IEnumerable logs)
{
var path = $"{id}-log.txt";
File.WriteAllLines(path, logs);
return Path.Combine(Directory.GetCurrentDirectory(), path);
}
///
/// Save the results to disk
///
/// The name of the results
/// The results to save
public virtual void SaveResults(string name, Result result)
{
File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), name), JsonConvert.SerializeObject(result, Formatting.Indented));
}
///
/// Sets the current alpha runtime statistics
///
/// The current alpha runtime statistics
public virtual void SetAlphaRuntimeStatistics(AlphaRuntimeStatistics statistics)
{
AlphaRuntimeStatistics = statistics;
}
///
/// Sets the current Data Manager instance
///
public virtual void SetDataManager(IDataFeedSubscriptionManager dataManager)
{
DataManager = dataManager;
}
}
}