public ActionResult DeleteConfirmed(long id)
        {
            VertexFactorsDb vertexFactorsDb = db.VertexFactorsDb.Find(id);

            db.VertexFactorsDb.Remove(vertexFactorsDb);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "vertex_id,id,date,betweeness_centrality,closeness_centrality,indegree_centrality,influence_range,outdegree_centrality,up_to_date")] VertexFactorsDb vertexFactorsDb)
 {
     if (ModelState.IsValid)
     {
         db.Entry(vertexFactorsDb).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.vertex_id = new SelectList(db.VertexDb, "id", "identifier", vertexFactorsDb.vertex_id);
     return(View(vertexFactorsDb));
 }
        // GET: VertexFactorsDbs/Details/5
        public ActionResult Details(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            VertexFactorsDb vertexFactorsDb = db.VertexFactorsDb.Find(id);

            if (vertexFactorsDb == null)
            {
                return(HttpNotFound());
            }
            return(View(vertexFactorsDb));
        }
        // GET: VertexFactorsDbs/Edit/5
        public ActionResult Edit(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            VertexFactorsDb vertexFactorsDb = db.VertexFactorsDb.Find(id);

            if (vertexFactorsDb == null)
            {
                return(HttpNotFound());
            }
            ViewBag.vertex_id = new SelectList(db.VertexDb, "id", "identifier", vertexFactorsDb.vertex_id);
            return(View(vertexFactorsDb));
        }
Example #5
0
        public IHttpActionResult CountAll(int id, string date)
        {
            Network  networkTemp = MakeNetworkFromDb(id, date, 1); //liczy zawsze z wierzchołkiem początkowym
            DateTime dateT       = DateTime.Parse(date);

            networkTemp.ClosenessCentrality2();
            networkTemp.InfluenceRange2();
            networkTemp.CentralityIn2();
            networkTemp.CentralityOut2();
            networkTemp.BetweennessCentrality2();

            var previousN = db.NetworkFactorsDb.SingleOrDefault(o => o.network_id == networkTemp.id && o.date == dateT && o.up_to_date);

            if (previousN != null)
            {
                var row_ = from o in db.NetworkFactorsDb
                           where o.network_id == networkTemp.id && o.date == dateT && o.up_to_date
                           select o;
                foreach (var o in row_)
                {
                    o.avg_indegree_centrality    = networkTemp.AverageFactor(1);
                    o.avg_outdegree_centrality   = networkTemp.AverageFactor(2);
                    o.avg_closeness_centrality   = networkTemp.AverageFactor(3);
                    o.avg_betweenness_centrality = networkTemp.AverageFactor(4);
                    o.avg_influence_range        = networkTemp.AverageFactor(5);
                    o.density         = networkTemp.Density();
                    o.bet_cen_count   = true;
                    o.clos_cen_count  = true;
                    o.density_count   = true;
                    o.ind_cen_count   = true;
                    o.inf_range_count = true;
                    o.out_cen_count   = true;
                }
                db.SaveChanges();
            }
            else
            {
                var rowN = new NetworkFactorsDb
                {
                    network_id = id,
                    avg_indegree_centrality    = networkTemp.AverageFactor(1),
                    avg_outdegree_centrality   = networkTemp.AverageFactor(2),
                    avg_closeness_centrality   = networkTemp.AverageFactor(3),
                    avg_betweenness_centrality = networkTemp.AverageFactor(4),
                    avg_influence_range        = networkTemp.AverageFactor(5),
                    density         = networkTemp.Density(),
                    date            = DateTime.Parse(date),
                    up_to_date      = true,
                    bet_cen_count   = true,
                    clos_cen_count  = true,
                    density_count   = true,
                    ind_cen_count   = true,
                    inf_range_count = true,
                    out_cen_count   = true
                };
                db.NetworkFactorsDb.Add(rowN);
                db.SaveChanges();
            }
            networkTemp.Normalize();
            foreach (Vertex vert in networkTemp.vertices)
            {
                //zmienione - nadpisuje stary wiersz
                var previous = db.VertexFactorsDb.SingleOrDefault(o => o.vertex_id == vert.id && o.date == dateT && o.up_to_date);
                if (previous != null)
                {
                    var row_ = from o in db.VertexFactorsDb where o.vertex_id == vert.id && o.date == dateT select o;
                    foreach (var o in row_)
                    {
                        o.betweenness_centrality = vert.betweennessCentralityValue;
                        o.closeness_centrality   = vert.closenessCentralityValue;
                        o.indegree_centrality    = vert.indegreeCentralityValue;
                        o.influence_range        = vert.influenceRangeValue;
                        o.outdegree_centrality   = vert.outdegreeCentralityValue;
                    }
                    db.SaveChanges();
                }
                else
                {
                    var row = new VertexFactorsDb
                    {
                        vertex_id = vert.id,
                        betweenness_centrality = vert.betweennessCentralityValue,
                        closeness_centrality   = vert.closenessCentralityValue,
                        indegree_centrality    = vert.indegreeCentralityValue,
                        influence_range        = vert.influenceRangeValue,
                        outdegree_centrality   = vert.outdegreeCentralityValue,
                        date       = DateTime.Parse(date),
                        up_to_date = true,
                        network_id = id
                    };
                    db.VertexFactorsDb.Add(row);
                    db.SaveChanges();
                }
            }


            return(Ok());
        }
Example #6
0
        public JsonResult <float> OutdegreeCentrality(int id, string date)
        {
            Network net = MakeNetworkFromDb(id, date, 1);

            net.CentralityOut2();
            DateTime dateT     = DateTime.Parse(date);
            var      outdegree = net.AverageFactor(2);
            var      previousN = db.NetworkFactorsDb.SingleOrDefault(o => o.network_id == net.id && o.date == dateT && o.up_to_date);

            if (previousN != null)
            {
                var row_ = from o in db.NetworkFactorsDb
                           where o.network_id == net.id && o.date == dateT && o.up_to_date
                           select o;
                foreach (var o in row_)
                {
                    o.avg_outdegree_centrality = outdegree;
                    o.out_cen_count            = true;
                }
                db.SaveChanges();
            }
            else
            {
                var rowN = new NetworkFactorsDb
                {
                    network_id = id,
                    avg_outdegree_centrality = outdegree,
                    date          = DateTime.Parse(date),
                    up_to_date    = true,
                    out_cen_count = true
                };
                db.NetworkFactorsDb.Add(rowN);
                db.SaveChanges();
            }
            net.Normalize();

            foreach (Vertex vert in net.vertices)
            {
                var previous = db.VertexFactorsDb.SingleOrDefault(o => o.vertex_id == vert.id && o.date == dateT && o.up_to_date);
                if (previous != null)
                {
                    var row_ = from o in db.VertexFactorsDb where o.vertex_id == vert.id && o.date == dateT select o;
                    foreach (var o in row_)
                    {
                        o.outdegree_centrality = vert.outdegreeCentralityValue;
                    }
                    db.SaveChanges();
                }
                else
                {
                    var row = new VertexFactorsDb
                    {
                        vertex_id            = vert.id,
                        outdegree_centrality = vert.outdegreeCentralityValue,
                        date       = DateTime.Parse(date),
                        up_to_date = true,
                        network_id = id
                    };
                    db.VertexFactorsDb.Add(row);
                    db.SaveChanges();
                }
            }

            return(Json(outdegree));
        }
Example #7
0
        public JsonResult <float> InfluenceRange(int id, string date)
        {
            Network net = MakeNetworkFromDb(id, date, 1);

            net.InfluenceRange2();
            DateTime dateT     = DateTime.Parse(date);
            var      influence = net.AverageFactor(5);
            var      previousN = db.NetworkFactorsDb.SingleOrDefault(o => o.network_id == net.id && o.date == dateT && o.up_to_date);

            if (previousN != null)
            {
                var row_ = from o in db.NetworkFactorsDb
                           where o.network_id == net.id && o.date == dateT && o.up_to_date
                           select o;
                foreach (var o in row_)
                {
                    o.avg_influence_range = influence;
                    o.inf_range_count     = true;
                }
                db.SaveChanges();
            }
            else
            {
                var rowN = new NetworkFactorsDb
                {
                    network_id          = id,
                    avg_influence_range = influence,
                    date            = DateTime.Parse(date),
                    up_to_date      = true,
                    inf_range_count = true
                };
                db.NetworkFactorsDb.Add(rowN);
                db.SaveChanges();
            }
            net.Normalize();

            foreach (Vertex vert in net.vertices)
            {
                var previous = db.VertexFactorsDb.SingleOrDefault(o => o.vertex_id == vert.id && o.date == dateT && o.up_to_date);
                if (previous != null)
                {
                    var row_ = from o in db.VertexFactorsDb where o.vertex_id == vert.id && o.date == dateT select o;
                    foreach (var o in row_)
                    {
                        o.influence_range = vert.influenceRangeValue;
                    }
                    db.SaveChanges();
                }
                else
                {
                    var row = new VertexFactorsDb
                    {
                        vertex_id       = vert.id,
                        influence_range = vert.influenceRangeValue,
                        date            = DateTime.Parse(date),
                        up_to_date      = true,
                        network_id      = id
                    };
                    db.VertexFactorsDb.Add(row);
                    db.SaveChanges();
                }
            }

            return(Json(influence));
        }
Example #8
0
        public JsonResult <float> BetweennessCentrality(int id, string date)
        {
            Network net = MakeNetworkFromDb(id, date, 1);

            net.BetweennessCentrality2();
            DateTime dateT = DateTime.Parse(date);

            var betweenness = net.AverageFactor(4);
            var previousN   = db.NetworkFactorsDb.SingleOrDefault(o => o.network_id == net.id && o.date == dateT && o.up_to_date);

            if (previousN != null)
            {
                var row_ = from o in db.NetworkFactorsDb
                           where o.network_id == net.id && o.date == dateT && o.up_to_date
                           select o;
                foreach (var o in row_)
                {
                    o.avg_betweenness_centrality = betweenness;
                    o.bet_cen_count = true;
                }
                db.SaveChanges();
            }
            else
            {
                var rowN = new NetworkFactorsDb
                {
                    network_id = id,
                    avg_betweenness_centrality = betweenness,
                    date          = DateTime.Parse(date),
                    up_to_date    = true,
                    bet_cen_count = true
                };
                db.NetworkFactorsDb.Add(rowN);
                db.SaveChanges();
            }

            net.Normalize();                      // normalizacja

            foreach (Vertex vert in net.vertices) //zapis do tablicy współczynników wierzchołków
            {
                var previous = db.VertexFactorsDb.SingleOrDefault(o => o.vertex_id == vert.id && o.date == dateT && o.up_to_date);
                if (previous != null)
                {
                    var row_ = from o in db.VertexFactorsDb where o.vertex_id == vert.id && o.date == dateT select o;
                    foreach (var o in row_)
                    {
                        o.betweenness_centrality = vert.betweennessCentralityValue;
                    }
                    db.SaveChanges();
                }
                else
                {
                    var row = new VertexFactorsDb
                    {
                        vertex_id = vert.id,
                        betweenness_centrality = vert.betweennessCentralityValue,
                        date       = DateTime.Parse(date),
                        up_to_date = true,
                        network_id = id
                    };
                    db.VertexFactorsDb.Add(row);
                    db.SaveChanges();
                }
            }

            return(Json(betweenness));
        }