Example #1
0
 public BellmanFord(WeightGraph graph) : this(graph.Length)
 {
     for (int i = 0; i < _n; i++)
     {
         _graph[i].AddRange(graph[i].Cast <IEdge>());
     }
 }
Example #2
0
 public WeightGraph(WeightGraph graph)
 {
     this.adjacencyMatrix = new long[graph.NodeNum, graph.NodeNum];
     foreach (var i in Enumerable.Range(0, graph.NodeNum))
     {
         foreach (var j in Enumerable.Range(0, graph.NodeNum))
         {
             this.adjacencyMatrix[i, j] = graph.GetLength(i, j);
         }
     }
     this.NodeNum = graph.NodeNum;
 }
Example #3
0
        /// <summary>
        /// ワーシャルフロイド法
        /// O(N^3)
        /// </summary>
        /// <param name="graph">グラフ</param>
        /// <param name="nodeNum">ノードの数</param>
        /// <returns>各ノード間の最短距離を辺として持つグラフ</returns>
        public static WeightGraph WarshallFloyd(WeightGraph graph)
        {
            var res = new WeightGraph(graph);

            foreach (var b in Enumerable.Range(0, graph.NodeNum))
            {
                foreach (var a in Enumerable.Range(0, graph.NodeNum))
                {
                    foreach (var c in Enumerable.Range(0, graph.NodeNum))
                    {
                        res.Add(a, c, Min(res.GetLength(a, c), res.GetLength(a, b) + res.GetLength(b, c)));
                    }
                }
            }
            return(res);
        }
        async Task UpdateUsersWeight()
        {
            data = await service.GetWeigths();

            if (data != null)
            {
                InvokeOnMainThread(delegate
                {
                    TableWeight.SeparatorStyle = UITableViewCellSeparatorStyle.None;
                    TableWeight.Hidden         = true;
                    WeightTableSource source   = new WeightTableSource(data);
                    TableWeight.Source         = source;
                    source.OnWeightSelected   += (sender, args) =>
                    {
                        WeightController newController = (WeightController)this.Storyboard.InstantiateViewController("weightID");
                        WeightController.Weight        = args.Weight;
                        newController.OnDeleteWeight  += async(sender2, args2) =>
                        {
                            if (await service.DeleteWeightIntoHealthStore(args2.Weight))
                            {
                                UpdateUsersWeight();
                            }
                            else
                            {
                                InvokeOnMainThread(delegate
                                {
                                    new UIAlertView("HealthKit", "No puede borrar este registro, ha sido creado por otra app", null, "OK", null).Show();
                                });
                            }
                        };
                        PresentViewController(newController, true, null);
                    };
                    TableWeight.ReloadData();
                    TableWeight.Hidden = false;
                    WeightGraph.SetData(data, 75, 66);
                    //WeightGraph.SetData(data, 95, 96);
                });
            }
        }
Example #5
0
        static void Main(string[] args)
        {
            string[] argTwoAccepted   = { "png", "svg", "ps" };
            string[] argThreeAccepted = { "genre", "artist", "music" };
            string[] argFourAccepted  = { "simple", "detailled", "weighted" };

            if (args.Length == 4)
            {
                if (!Directory.Exists(args[0]))
                {
                    Console.WriteLine("Argument 1 : Your directory does not exist");
                    Console.ReadKey();
                    return;
                }

                if (Array.IndexOf(argTwoAccepted, args[1]) == -1)
                {
                    Console.WriteLine("Argument 2 : ps|png|svg");
                    Console.ReadKey();
                    return;
                }

                if (Array.IndexOf(argThreeAccepted, args[2]) == -1)
                {
                    Console.WriteLine("Argument 3 : Invalide : genre|artist|music");
                    Console.WriteLine("music is applied ...");
                }

                if (Array.IndexOf(argFourAccepted, args[3]) == -1)
                {
                    Console.WriteLine("Argument 3 : Invalide : simple|detailled|weighted");
                    Console.ReadKey();
                    return;
                }

                IndexationProcessus indexation = new IndexationProcessus(args[0]);
                IGraph graph = null;

                if (args[3] == "simple")
                {
                    graph = new SimpleGraph(indexation.Musics, indexation.Artists, indexation.Genres, args[1]);
                }
                else if (args[3] == "detailled")
                {
                    graph = new DetailledGraph(indexation.Musics, indexation.Artists, indexation.Genres, args[1]);
                }
                else if (args[3] == "weighted")
                {
                    graph = new WeightGraph(indexation.Musics, indexation.Artists, indexation.Genres, args[1]);
                }

                if (args[2].Equals("genre"))
                {
                    graph.GenerateGenreGraph();
                }
                else if (args[2].Equals("artist"))
                {
                    graph.GenerateArtistGraph();
                }
                else
                {
                    graph.GenerateMusicGraph();
                }

                Top top = new Top(indexation.Artists, indexation.Genres, indexation.Years);
                top.ShowGlobalStats(args[0], indexation.Musics);
                top.ShowTopArtists();
                top.ShowTopTags();
                top.ShowTopYear();

                Console.ReadKey();
            }
            else
            {
                Console.WriteLine("Info : playlist.exe [path to music folder] [svg|png|ps] [genre|artist|music:default]");
            }
        }
Example #6
0
 public DijkstraShortestPath(WeightGraph graph)
 {
     _graph = graph;
 }
        public IActionResult Patient(string id, DateTime?dataTime = null, string filtering = null)
        {
            var observation = GetObservations(id);



            var dbObservation = new List <ListObservation>();

            foreach (var unit in observation)
            {
                if (unit.resourceType == "Observation")
                {
                    var baseUnit = _iwmdbContext.Observation.Where(x => x.Id == unit.id && x.ResourceType == unit.resourceType);
                    if (baseUnit.Count() > 1)
                    {
                        var maxUnit     = baseUnit.Max(x => x.VersionId);
                        var HighestUnit = baseUnit.First(x => x.VersionId == maxUnit);

                        var newUnit = unit;

                        if (HighestUnit.LastUpdated != null)
                        {
                            newUnit.meta.lastUpdated = (DateTime)HighestUnit.LastUpdated;
                            newUnit.DataWasEdited    = true;
                        }
                        if (HighestUnit.Text != null)
                        {
                            newUnit.code.text     = HighestUnit.Text;
                            newUnit.TextWasEdited = true;
                        }
                        if (HighestUnit.Value != null)
                        {
                            newUnit.valueQuantity.value = (double)HighestUnit.Value;
                            newUnit.ValueWasEdited      = true;
                        }

                        newUnit.OldListObservations = baseUnit.OrderByDescending(x => x.VersionId).Skip(1).Select(y =>
                                                                                                                  new ListObservation
                        {
                            code = new Code {
                                text = y.Text
                            },
                            meta = new Meta {
                                lastUpdated = (DateTime)y.LastUpdated
                            },
                            valueQuantity = new ValueQuantity {
                                value = (double)y.Value
                            }
                        }).ToList();

                        dbObservation.Add(newUnit);
                    }
                    if (baseUnit.Count() == 1)
                    {
                        var baseUnitFirst = baseUnit.First();
                        var newUnit       = unit;

                        if (baseUnitFirst.LastUpdated != null)
                        {
                            newUnit.meta.lastUpdated = (DateTime)baseUnitFirst.LastUpdated;
                        }
                        if (baseUnitFirst.Text != null)
                        {
                            newUnit.code.text = baseUnitFirst.Text;
                        }
                        if (baseUnitFirst.Value != null)
                        {
                            newUnit.valueQuantity.value = (double)baseUnitFirst.Value;
                        }
                        dbObservation.Add(newUnit);
                    }
                    if (baseUnit.Count() == 0)
                    {
                        int ver = 1;
                        int.TryParse(unit.meta.versionId, out ver);
                        var newObservation = new Observation
                        {
                            Id           = unit.id,
                            LastUpdated  = unit.meta.lastUpdated,
                            LastChanged  = unit.meta.lastUpdated,
                            ResourceType = unit.resourceType,
                            Text         = unit.code.text,
                            Value        = (decimal)unit.valueQuantity.value,
                            VersionId    = ver
                        };
                        _iwmdbContext.Observation.Add(newObservation);
                        _iwmdbContext.SaveChanges();
                        dbObservation.Add(unit);
                    }
                }
                else if (unit.resourceType == "MedicationStatement")
                {
                    var baseUnit = _iwmdbContext.Observation.Where(x => x.Id == unit.id && x.ResourceType == unit.resourceType);
                    if (baseUnit.Count() > 1)
                    {
                        var maxUnit     = baseUnit.Max(x => x.VersionId);
                        var HighestUnit = baseUnit.First(x => x.VersionId == maxUnit);

                        var newUnit = unit;

                        if (HighestUnit.LastUpdated != null)
                        {
                            newUnit.meta.lastUpdated = (DateTime)HighestUnit.LastUpdated;
                            newUnit.DataWasEdited    = true;
                        }
                        if (HighestUnit.Text != null)
                        {
                            newUnit.medicationCodeableConcept.text = HighestUnit.Text;
                            newUnit.TextWasEdited = true;
                        }
                        if (HighestUnit.Value != null)
                        {
                            newUnit.dosage.First().doseQuantity.value = (int)HighestUnit.Value;
                            newUnit.ValueWasEdited = true;
                        }
                        newUnit.OldListObservations = baseUnit.OrderByDescending(x => x.VersionId).Skip(1).Select(y =>
                                                                                                                  new ListObservation
                        {
                            medicationCodeableConcept = new MedicationCodeableConcept {
                                text = y.Text
                            },
                            meta = new Meta {
                                lastUpdated = (DateTime)y.LastUpdated
                            },
                            dosage = new List <Dosage> {
                                new Dosage {
                                    doseQuantity = new DoseQuantity {
                                        value = (int)y.Value
                                    }
                                }
                            }
                        }).ToList();

                        dbObservation.Add(newUnit);
                    }
                    if (baseUnit.Count() == 1)
                    {
                        var baseUnitFirst = baseUnit.First();
                        var newUnit       = unit;

                        if (baseUnitFirst.LastUpdated != null)
                        {
                            newUnit.meta.lastUpdated = (DateTime)baseUnitFirst.LastUpdated;
                        }
                        if (baseUnitFirst.Text != null)
                        {
                            newUnit.medicationCodeableConcept.text = baseUnitFirst.Text;
                        }
                        if (baseUnitFirst.Value != null)
                        {
                            newUnit.dosage.First().doseQuantity.value = (int)baseUnitFirst.Value;
                        }
                        dbObservation.Add(newUnit);
                    }
                    if (baseUnit.Count() == 0)
                    {
                        int ver = 1;
                        int.TryParse(unit.meta.versionId, out ver);
                        var newObservation = new Observation
                        {
                            Id           = unit.id,
                            LastUpdated  = unit.meta.lastUpdated,
                            LastChanged  = unit.meta.lastUpdated,
                            ResourceType = unit.resourceType,
                            Text         = unit.medicationCodeableConcept.text,
                            Value        = unit.dosage.First().doseQuantity.value,
                            VersionId    = ver
                        };
                        _iwmdbContext.Observation.Add(newObservation);
                        _iwmdbContext.SaveChanges();
                        dbObservation.Add(unit);
                    }
                }
            }

            dbObservation = dbObservation.OrderBy(x => x.meta.lastUpdated).ToList();

            DateTime last = DateTime.Now;

            if (filtering == "Last Week")
            {
                last = dataTime.Value.AddDays(-7);
            }
            if (filtering == "Last Year")
            {
                last = dataTime.Value.AddDays(-365);
            }
            if (filtering == "Last Month")
            {
                last = dataTime.Value.AddDays(-31);
            }
            if (filtering == "All")
            {
                last = dataTime.Value.AddDays(-5000);
            }

            if (filtering != null)
            {
                dbObservation = dbObservation
                                .Where(x => x.meta.lastUpdated > last && x.meta.lastUpdated < dataTime)
                                .ToList();


                WeightGraphs = new WeightGraph();
                var values = dbObservation
                             .Where(y => y.resourceType == "Observation")
                             .Where(x => x.code.coding.First().code == "3141-9")
                             .Where(x => x.meta.lastUpdated > last && x.meta.lastUpdated < dataTime)
                             .Select(t => (float)t.valueQuantity.value)
                             .ToList();

                var dateTimes = dbObservation
                                .Where(y => y.resourceType == "Observation")
                                .Where(x => x.code.coding.First().code == "3141-9")
                                .Where(x => x.meta.lastUpdated > last && x.meta.lastUpdated < dataTime)
                                .Select(t => t.meta.lastUpdated)
                                .ToList();

                WeightGraphs.DateTime = dateTimes;
                WeightGraphs.Weight   = values;
                WeightGraphs.Max      = filtering;
            }
            else
            {
                WeightGraphs = new WeightGraph();
                var values = dbObservation
                             .Where(y => y.resourceType == "Observation")
                             .Where(x => x.code.coding.First().code == "3141-9")
                             .Select(t => (float)t.valueQuantity.value)
                             .ToList();

                var dateTimes = dbObservation
                                .Where(y => y.resourceType == "Observation")
                                .Where(x => x.code.coding.First().code == "3141-9")
                                .Select(t => t.meta.lastUpdated)
                                .ToList();

                WeightGraphs.DateTime = dateTimes;
                WeightGraphs.Weight   = values;
            }



            dbObservation = dbObservation.OrderByDescending(x => x.meta.lastUpdated).ToList();

            var viewModel = new PatientViewModel()
            {
                Units = dbObservation, PatientId = id
            };

            return(View(viewModel));
        }