Ejemplo n.º 1
0
        public static bool updateSightings()
        {
            DateTime  now      = DateTime.Now;
            DataTable resultdt = DbConnector.GetSpeciesFromDB();

            if (resultdt == null)
            {
                return(false);
            }
            foreach (DataRow row in resultdt.Rows)
            {
                String birdTableName = "testdb.bird" + row["speciename"].ToString();
                birdTableName = birdTableName.Replace("-", "");
                String clearQuery = "DELETE from " + birdTableName + ";";
                executeNonQuery(clearQuery);


                string sightingsQuery = "SELECT * FROM testdb.sightings WHERE specie = '@name';";
                sightingsQuery = sightingsQuery.Replace("@name", row["speciename"].ToString());
                DataTable birds = executeQuery(sightingsQuery);
                if (birds == null)
                {
                    return(false);
                }
                var freshBirds = new List <BirdSighting>();
                foreach (DataRow birbRow in birds.Rows)
                {
                    DateTime time = Convert.ToDateTime(birbRow["timestamp"]);
                    TimeSpan span = now.Subtract(time);
                    double   lon  = Convert.ToDouble(birbRow["longitudecoord"]);
                    double   lat  = Convert.ToDouble(birbRow["latitudecoord"]);
                    if (span.CompareTo(TimeSpan.FromDays(FRESH_BIRD_TIMESPAN)) < 0)
                    {
                        var sighting = new BirdSighting
                        {
                            username       = "",
                            specie         = row["speciename"].ToString(),
                            longitudecoord = lon,
                            latitudecoord  = lat,
                            comment        = "",
                            timestamp      = now
                        };
                        freshBirds.Add(sighting);
                    }
                }
                double[][] clusters    = KekMeansLocationProviderAdapter.ClusterPartitions(freshBirds.ToList <LocationProvider>(), KekMeansLocationProviderAdapter.DEFAULT_CLUSTER_AMOUNT);
                string     insertQuery = "INSERT INTO " + birdTableName + " VALUES(@latitude, @longtitude);";
                for (int i = 0; i < clusters.Length; i++)
                {
                    string insertCopy = String.Copy(insertQuery);
                    insertCopy = insertCopy.Replace("@latitude", clusters[i][0].ToString());
                    insertCopy = insertCopy.Replace("@longtitude", clusters[i][1].ToString());
                    executeNonQuery(insertCopy);
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        public IEnumerable <Tower> getTowersClustered()
        {
            //TODO: Only needs to fetch coordinates from database?
            IEnumerable <Tower> Towers = GetTowers();

            double[][] clusters = KekMeansLocationProviderAdapter.ClusterPartitions(Towers.ToList <LocationProvider>(), KekMeansLocationProviderAdapter.DEFAULT_CLUSTER_AMOUNT);

            var ResultList = new List <Tower>();

            for (int i = 0; i < clusters.Length; i++)
            {
                Tower cluster = new Tower
                {
                    id             = i.ToString(),
                    municipal      = "testipesti",
                    towername      = "Cluster" + i.ToString(),
                    latitudecoord  = clusters[i][0].ToString(),
                    longitudecoord = clusters[i][1].ToString()
                };
                ResultList.Add(cluster);
            }
            return(ResultList);
        }