/// <summary> /// Convert the source (fake) to data /// It is to fake data coming as a xml file from either web or local /// </summary> /// <returns></returns> public override ISourceData ConvertSourceToData() { ISourceData data = CreateSourceData(); using (StreamReader reader = new StreamReader(FilePath)) { XDocument xdoc = XDocument.Load(reader.BaseStream); var first = (from element in xdoc.Root.Elements("day") where (string)element.Attribute("name") == "current" select new { Name = (string)element.Attribute("name"), Temperature = (double)element.Attribute("temperature"), Degree = (string)element.Attribute("degree"), }).ToList().First(); if (first != null) { data.Name = first.Name; data.Reading = first.Temperature; data.Unit = ConvertToTempUnit(first.Degree); } } return(data); }
public void Setup() { _episodeMapper = Substitute.For <IEpisodeMapper>(); _sources = Substitute.For <ISources>(); _mappingList = Substitute.For <IMappingList>(); _embyData = Substitute.For <IEmbyItemData>(); _embyData.Identifier.Returns(new ItemIdentifier(67, 53, "Name")); _embyData.Language.Returns("en"); var aniDbSource = Substitute.For <IAniDbSource>(); _sources.AniDb.Returns(aniDbSource); var tvDbSource = Substitute.For <ITvDbSource>(); _sources.TvDb.Returns(tvDbSource); _tvDbSourceData = Substitute.For <ISourceData <TvDbEpisodeData> >(); _mediaItem = Substitute.For <IMediaItem>(); _mediaItem.EmbyData.Returns(_embyData); _mediaItem.ItemType.Returns(MediaItemTypes.Episode); SetUpTvDbEpisodeData(56, 67, 53); _noMappingResult = new ProcessFailedResult("", "", null, ""); _mappingList.GetSeriesMappingsFromTvDb(Arg.Any <int>(), Arg.Any <ProcessResultContext>()) .Returns(Left <ProcessFailedResult, IEnumerable <ISeriesMapping> >(_noMappingResult)); }
public Pixel Map(ISourceData data) { return(data.GetPixel(0, 0) - data.GetPixel(1, 0) - data.GetPixel(-1, 0) - data.GetPixel(0, 1) - (data.GetPixel(0, -1) * (1 / 64d))); }
public Pixel Map(ISourceData data) { Pixel p = data.GetPixel(0, 0); int r = PixelUtils.Clamp((int)((255.0 * Math.Pow(p.R / 255.0, 1.0 / _gammaCorrection)) + 0.5), 255, 0); int g = PixelUtils.Clamp((int)((255.0 * Math.Pow(p.G / 255.0, 1.0 / _gammaCorrection)) + 0.5), 255, 0); int b = PixelUtils.Clamp((int)((255.0 * Math.Pow(p.B / 255.0, 1.0 / _gammaCorrection)) + 0.5), 255, 0); int a = PixelUtils.Clamp((int)((255.0 * Math.Pow(p.A / 255.0, 1.0 / _gammaCorrection)) + 0.5), 255, 0); return(new Pixel(r, g, b, a)); }
public Sources(string azureConnectionString) { var builder = new ConfigurationBuilder(); IConfiguration configuration = builder.Build(); _fileStorage = new AzureFileStorageServiceCommon(configuration); _fileStorage.SetConnectionString(azureConnectionString); _azureDataTables = new AzureDataTable(configuration); _azureDataTables.SetConnectionString(azureConnectionString); _sourceData = new SourceData(_azureDataTables); }
public Pixel Map(ISourceData data) { return(Pixel.GetMeanValuePixel( data.GetPixel(0 * amount, -1 * amount), data.GetPixel(1 * amount, -1 * amount), data.GetPixel(1 * amount, 0 * amount), data.GetPixel(1 * amount, 1 * amount), data.GetPixel(0 * amount, 1 * amount), data.GetPixel(-1 * amount, -1 * amount), data.GetPixel(-1 * amount, 0 * amount), data.GetPixel(-1 * amount, 1 * amount))); }
/// <summary> /// Create a new <see cref="MediaItem" /> /// </summary> /// <param name="embyData">The name of the item as originally provided by Emby</param> /// <param name="itemType">The type of the media item</param> /// <param name="sourceData">The metadata from the source used to initially identify this media item</param> public MediaItem(IEmbyItemData embyData, IMediaItemType itemType, ISourceData sourceData) { if (sourceData == null) { throw new ArgumentNullException(nameof(sourceData)); } this.EmbyData = embyData ?? throw new ArgumentNullException(nameof(embyData)); this.ItemType = itemType; this.sourceData = ImmutableDictionary <string, ISourceData> .Empty.Add(sourceData.Source.Name, sourceData); }
public static ISourceDataLoader SourceDataLoader(IMediaItem mediaItem, ISourceData dependencySourceData, string sourceName) { var sourceDataLoader = Substitute.For <ISourceDataLoader>(); var producedSourceData = SourceData(sourceName); sourceDataLoader.CanLoadFrom(dependencySourceData).Returns(true); sourceDataLoader.CanLoadFrom(Arg.Is <object>(o => o != dependencySourceData)).Returns(false); sourceDataLoader.LoadFrom(mediaItem, dependencySourceData) .ReturnsForAnyArgs(Right <ProcessFailedResult, ISourceData>(producedSourceData)); return(sourceDataLoader); }
public Either <ProcessFailedResult, IMediaItem> AddData(ISourceData sourceData) { if (_sourceData.ContainsKey(sourceData.Source.Name)) { var failedResult = new ProcessFailedResult(sourceData.Source.Name, sourceData.Identifier.Name, ItemType, "Cannot add data for a source more than once"); return(Left <ProcessFailedResult, IMediaItem>(failedResult)); } return(Right <ProcessFailedResult, IMediaItem>(new MediaItem(EmbyData, ItemType, _sourceData.Add(sourceData.Source.Name, sourceData)))); }
public Pixel Map(ISourceData data) { Pixel p0 = data.GetPixel(0, 0); Pixel p1 = data.GetPixel(-1 * _amount, -1 * _amount); Pixel p2 = data.GetPixel(1 * _amount, 1 * _amount); Pixel p3 = data.GetPixel(-1 * _amount, 1 * _amount); Pixel p4 = data.GetPixel(1 * _amount, -1 * _amount); int r = ((p1.R + p2.R + p3.R + p4.R + p0.R)) / 5; int g = ((p1.G + p2.G + p3.G + p4.G + p0.G)) / 5; int b = ((p1.B + p2.B + p3.B + p4.B + p0.B)) / 5; return(new Pixel(r, g, b, 255)); }
/// <summary> /// Get the latest tempearture from external source /// </summary> /// <returns></returns> public void GetLatestTemperature() { ISourceData sourceData = ExternalSource.ConvertSourceToData(); if (sourceData.Unit == TemperatureUnit.Unknown) { throw new ThermometerUnknownUnitException(); } CurrentTemperature = new TemperatureUnitConvertor().ConvertToNewReading( sourceData.Reading, from: sourceData.Unit, to: CurrentTempUnit); // Populate to thresholds ThresholdsModel.PopulateTempUnitToSettings(CurrentTempUnit); }
private Either <ProcessFailedResult, MetadataResult <TEmbyItem> > SetIndexes(ISourceData librarySourceData, MetadataResult <TEmbyItem> target) { return(Right <ProcessFailedResult, MetadataResult <TEmbyItem> >(target) .Map(r => librarySourceData.Identifier.Index .Map(index => { r.Item.IndexNumber = index; return r; }) .Match(r2 => librarySourceData.Identifier.ParentIndex.Match(parentIndex => { r2.Item.ParentIndexNumber = parentIndex; return r2; }, () => r2), () => r))); }
public override ISourceData ConvertSourceToData() { ISourceData data = CreateSourceData(); using (StreamReader reader = new StreamReader(FilePath)) { string json = reader.ReadToEnd(); JsonWholeData objectList = JsonConvert.DeserializeObject <JsonWholeData>(json); //foreach (JsonSourceData item in objectList.thisss) //{ // if (item.Name == "current") // { // data.Name = item.Name; // data.Reading = item.Reading; // data.Unit = ConvertToTempUnit(item); /////// for now... // break; // } //} } return(data); }
public Pixel Map(ISourceData data) { double factor = _amount; Pixel[,] pixelMatrix = PixelUtils.GetPixelMatrix(data, 1); if (factor > 10) { factor = 10; } if (factor <= 0) { factor = 0.1d; } bias = 2.0; int red = 0; int green = 0; int blue = 0; int dimLength = pixelMatrix.GetLength(0); for (int x = 0; x < dimLength; x++) { for (int y = 0; y < dimLength; y++) { red += pixelMatrix[x, y].R * filterMatrix[x, y]; green += pixelMatrix[x, y].G * filterMatrix[x, y]; blue += pixelMatrix[x, y].B * filterMatrix[x, y]; } } int r = PixelUtils.Clamp((int)((factor * red) + bias), 255, 0); int g = PixelUtils.Clamp((int)((factor * green) + bias), 255, 0); int b = PixelUtils.Clamp((int)((factor * blue) + bias), 255, 0); return(new Pixel(r, g, b, pixelMatrix[1, 1].A)); }
/// <summary> /// /// </summary> /// <param name="data"></param> /// <param name="scale">The number of surounding pixels. Input 1 yeals a 3x3 matrix</param> /// <returns></returns> public static Pixel[,] GetPixelMatrix(ISourceData data, int scale) { if (scale < 1) { scale = 1; } int dimLength = scale * 3; Pixel[,] matrix = new Pixel[dimLength, dimLength]; for (int r = 0; r < dimLength; r++) { int y = r - 1; for (int i = 0; i < dimLength; i++) { int x = i - 1; matrix[r, i] = data.GetPixel(x, y); } } //matrix[0, 0] = data.GetPixel(-1, -1); //matrix[0, 1] = data.GetPixel(0, -1); //matrix[0, 2] = data.GetPixel(1, -1); //matrix[1, 0] = data.GetPixel(-1, 0); //matrix[1, 1] = data.GetPixel(0, 0); //matrix[1, 2] = data.GetPixel(1, 0); //matrix[2, 0] = data.GetPixel(-1, 1); //matrix[2, 1] = data.GetPixel(0, 1); //matrix[2, 2] = data.GetPixel(1, 1); return(matrix); }
private Either <ProcessFailedResult, MetadataResult <TEmbyItem> > SetIdentity(ISourceData librarySourceData, MetadataResult <TEmbyItem> target, IPropertyMappingCollection propertyMappings, SourceName librarySourceName, ProcessResultContext resultContext) { return(this.SetIndexes(librarySourceData, target) .Bind(r => this.SetName(librarySourceData.Data, r, propertyMappings, librarySourceName, resultContext))); }
//TODO public Pixel Map(ISourceData data) { return(data.GetPixel(0, 0)); }
public Pixel Map(ISourceData data) { //TODO implement Gaussian filter return(data.GetPixel(0, 0)); }