Esempio n. 1
0
        public void TestGetTimeMetadata()
        {
            IList <NycTimeResolution> data = NychanisHelper.GetTimeMetadata();

            DumpResults(data);
            Assert.AreEqual(3, data.Count, "Wrong number of timeframes.");
        }
Esempio n. 2
0
        protected override void InternalGET(System.Web.HttpContext context, HandlerTimedCache cache)
        {
            IList <SecurityRole> roles = UserHelper.GetUserRoles(context.User.Identity.Name);
            //Get the paging parameters...
            int page     = WebUtil.ParseIntParam(context, "page");
            int pageSize = WebUtil.ParseIntParam(context, "pageSize");

            // Check to see if this is a csv export request.  Runs the normal query (with no paging).
            bool csv = false;

            WebUtil.ParseOptionalBoolParam(context, "csv", ref csv);

            // If this is csv, we want all data - override any paging
            if (csv)
            {
                page     = -1;
                pageSize = -1;
            }

            // Now get the ordering parameters, if specified.
            int sortCol = -1;

            WebUtil.ParseOptionalIntParam(context, "sortBy", ref sortCol);
            SortType?sortDir = null;

            if (sortCol >= 0)
            {
                // Default is ascending sort, passing false means descending.
                bool ascending = true;
                WebUtil.ParseOptionalBoolParam(context, "sortasc", ref ascending);
                sortDir = ascending ? SortType.Asc : SortType.Desc;
            }

            string            indicatorId = WebUtil.GetParam(context, "indicator", false);
            NycResolutionType resolution  = WebUtil.ParseEnumParam <NycResolutionType>(context, "resolution");
            NycTimeframeType  timetype    = WebUtil.ParseEnumParam <NycTimeframeType>(context, "timetype");
            int minyear = WebUtil.ParseIntParam(context, "minyear");
            int maxyear = WebUtil.ParseIntParam(context, "maxyear");

            // These two params are for "scope".  These should be "ActualId" not "UID".
            string borough    = WebUtil.GetParam(context, "borough", true);
            string subborough = WebUtil.GetParam(context, "subborough", true);

            NycResultsWithMetadata list = NychanisHelper.Query(indicatorId, resolution, timetype, minyear, maxyear, borough, subborough, sortCol, sortDir, pageSize, page);

            // If this was a csv request, format it and return it instead
            if (csv)
            {
                // Generate actual csv data, determine if this is groupby'd or not
                string export = NychanisHelper.ResultsAsCsv(list, indicatorId);

                // Setup the response to handle this type of request
                context.Response.AddHeader("Content-Disposition", "attachment;filename=Furman_Center_Neighborhood_Info.csv");
                context.Response.ContentType = "text/csv";
                context.Response.Write(export);
                return;
            }
            // Return the results to the client
            context.Response.Write(WebUtil.ObjectToJson(list));
        }
Esempio n. 3
0
        public void TestContextRowsCity()
        {
            object indicatorId             = 201;
            NycResultsWithMetadata results = NychanisHelper.Query(indicatorId, NycResolutionType.City, NycTimeframeType.Year, 1999, 2009,
                                                                  null, null, 0, SortType.Asc, -1, -1);

            Assert.IsNull(results.ContextRows, "City should have no context rows.");
        }
Esempio n. 4
0
        public void TestMapLegendNoScope()
        {
            object indicatorId             = 201;
            NycResultsWithMetadata results = NychanisHelper.Query(indicatorId, NycResolutionType.CensusTract, NycTimeframeType.Year, 2005, 2008,
                                                                  null, null, 0, SortType.Asc, -1, -1);

            Assert.IsNotNull(results.LegendInfo, "Should have a Legend.");
            Assert.Greater(results.LegendInfo.Elements.Count, 0, "Legend should have more than 0 values");
        }
Esempio n. 5
0
        public void TestLegendList()
        {
            NycLegendInfo info = NychanisHelper.GenerateLegendList(_indicatorDao.GetFirst("UID", 201), NycResolutionType.Borough);

            Assert.AreEqual("percent", info.ValueType, "Wrong type for values.");
            Assert.IsNotNull(info, "Legend info was null.");
            Assert.IsNotNull(info.Elements, "Elements list was null.");
            AssertLegendValueList(new float[] { 2.52f, 4.20f, 5.79f, 7.47f, 9.06f, 10.75f, 12.43f }, info);
        }
Esempio n. 6
0
        public void TestContextRowsNoScope()
        {
            object indicatorId             = 201;
            NycResultsWithMetadata results = NychanisHelper.Query(indicatorId, NycResolutionType.CensusTract, NycTimeframeType.Year, 1999, 2009,
                                                                  null, null, 0, SortType.Asc, -1, -1);

            Assert.IsNotNull(results.ContextRows, "Context rows should be populated.");
            Assert.AreEqual(1, results.ContextRows.Count, "Should have a context row.");
            Assert.AreEqual("New York City", results.ContextRows[0][0], "Should be a context row for NY (city).");
        }
Esempio n. 7
0
        public void TestPagingPastTheEnd()
        {
            // Should return nothing.
            object indicatorId             = 10;
            int    numPerPage              = 10;
            NycResultsWithMetadata page500 = NychanisHelper.Query(indicatorId, NycResolutionType.SubBorough, NycTimeframeType.Year, 1999, 2009, null, null, 0, SortType.Asc, numPerPage, 500);

            Assert.AreEqual(0, page500.Values.Count, "Page 500 should be past the end, so we should get no results.");
            Assert.Greater(page500.TotalResults, numPerPage, "Total results should have been higher than what is returned on page 500.");
        }
Esempio n. 8
0
        public void TestScopeByBorough()
        {
            object indicatorId             = 10;
            int    borough                 = 3;
            NycResultsWithMetadata results = NychanisHelper.Query(indicatorId, NycResolutionType.Borough, NycTimeframeType.Year, 1999, 2009,
                                                                  borough, null, 0, SortType.Asc, -1, -1);

            Assert.AreEqual(1, results.Values.Count, "Wrong value for Total Results, a single borough [Manhattan] should have been returned");
            Assert.AreEqual("Manhattan", results.Values[0][0], "Results should have been limited to Manhattan, but were not.");
        }
Esempio n. 9
0
        public void TestOrderedResults()
        {
            object   indicatorId           = 10;
            int      sortCol               = 0;
            SortType type                  = SortType.Desc;
            NycResultsWithMetadata results =
                NychanisHelper.Query(indicatorId, NycResolutionType.Borough, NycTimeframeType.Year, 1970, 2020, null, null, sortCol, type, -1, -1);

            DumpResults(results);
            AssertOrdering(results.Values, sortCol, type);
        }
Esempio n. 10
0
        public void TestScopeByBoroughAndSubborough()
        {
            object indicatorId             = 10;
            int    borough                 = 3;   // Manhattan
            int    subbourough             = 308; // Central Harlem
            NycResultsWithMetadata results = NychanisHelper.Query(indicatorId, NycResolutionType.SubBorough, NycTimeframeType.Year, 1999, 2009,
                                                                  borough, subbourough, 0, SortType.Asc, -1, -1);

            Assert.AreEqual(1, results.Values.Count, "Wrong value for Total Results, a single SBA [Central Harlem] should have been returned.");
            Assert.AreEqual("Central Harlem", results.Values[0][0], "Results should have been limited to Central Harlem, but were not.");
        }
Esempio n. 11
0
        public void TestMapLegendSubBorough()
        {
            object indicatorId             = 201;
            int    borough                 = 3;   // Manhattan
            int    subbourough             = 308; // Central Harlem
            NycResultsWithMetadata results = NychanisHelper.Query(indicatorId, NycResolutionType.CensusTract, NycTimeframeType.Year, 2005, 2008,
                                                                  borough, subbourough, 0, SortType.Asc, -1, -1);

            Assert.IsNotNull(results.LegendInfo, "Should have a Legend.");
            Assert.Greater(results.LegendInfo.Elements.Count, 0, "Legend should have more than 0 values");
        }
Esempio n. 12
0
        public void TestCsvExport()
        {
            object indicatorId             = 201;
            int    borough                 = 3;   // Manhattan
            int    subbourough             = 308; // Central Harlem
            NycResultsWithMetadata results = NychanisHelper.Query(indicatorId, NycResolutionType.CensusTract, NycTimeframeType.Year, 1999, 2009,
                                                                  borough, subbourough, 0, SortType.Asc, -1, -1);

            string csv = NychanisHelper.ResultsAsCsv(results, indicatorId.ToString());

            Assert.IsNotEmpty(csv, "CSV Export should be populated.");
        }
Esempio n. 13
0
        public void TestSld2()
        {
            object indicatorId = 362;
            object timeId      = 0;
            string sld         = NychanisHelper.GenerateSld(indicatorId, NycResolutionType.SubBorough,
                                                            timeId, null, null);

            Console.WriteLine(sld);
            Assert.IsNotNull(sld, "Got null SLD.");
            Assert.Greater(sld.Length, 500, "SLD should be a large blob of XML...");
            Assert.Less(sld.Length, 2000, "SLD should be a large blob of XML...");
        }
Esempio n. 14
0
        public void TestSld()
        {
            object indicatorId = 201;
            object timeId      = 181;
            string sld         = NychanisHelper.GenerateSld(indicatorId, NycResolutionType.CensusTract,
                                                            timeId, null, null);

            Console.WriteLine(sld);
            Assert.IsNotNull(sld, "Got null SLD.");
            Assert.Greater(sld.Length, 100000, "SLD should be a large blob of XML...");
            Assert.Less(sld.Length, 1000000, "SLD should be a large blob of XML...");
        }
Esempio n. 15
0
        public void TestSldWithScope()
        {
            object indicatorId = 201;
            object timeId      = 181;
            int    borough     = 3; // Manhattan
            string sld         = NychanisHelper.GenerateSld(indicatorId, NycResolutionType.CensusTract,
                                                            timeId, borough, null);

            Console.WriteLine(sld);
            Assert.IsNotNull(sld, "Got null SLD.");
            Assert.Greater(sld.Length, 10000, "SLD should be a medium blob of XML...");
            Assert.Less(sld.Length, 100000, "SLD should be a medium blob of XML...");
        }
Esempio n. 16
0
        public void TestGetResolutionMetadata()
        {
            IList <NycResolution> data = NychanisHelper.GetResolutionMetadata();

            foreach (NycResolution res in data)
            {
                Console.WriteLine(res);
                DumpResults(res.Geographies, "    ");
                Assert.Greater(res.Geographies.Count, 0, "Should have been some geographies.");
            }
            Assert.AreEqual(Enum.GetValues(typeof(NycResolutionType)).Length, data.Count,
                            "Wrong number of resolutions.");
        }
Esempio n. 17
0
        public void TestContextRowsBoroughAndSBA()
        {
            object indicatorId             = 201;
            int    borough                 = 3;   // Manhattan
            int    subbourough             = 308; // Central Harlem
            NycResultsWithMetadata results = NychanisHelper.Query(indicatorId, NycResolutionType.CensusTract, NycTimeframeType.Year, 1999, 2009,
                                                                  borough, subbourough, 0, SortType.Asc, -1, -1);

            Assert.IsNotNull(results.ContextRows, "Context rows should be populated.");
            Assert.AreEqual(3, results.ContextRows.Count, "Should have a context row.");
            Assert.AreEqual("New York City", results.ContextRows[0][0], "Should be a context row for NY (city).");
            Assert.AreEqual("Manhattan", results.ContextRows[1][0], "Should be a context row for Manhattan (borough).");
            Assert.AreEqual("Central Harlem", results.ContextRows[2][0], "Should be a context row for Central Harlem (SBA).");
        }
Esempio n. 18
0
        protected override void InternalGET(HttpContext context, HandlerTimedCache cache)
        {
            string            indicatorId = WebUtil.GetParam(context, "indicator", false);
            NycResolutionType resolution  = WebUtil.ParseEnumParam <NycResolutionType>(context, "resolution");
            string            timeId      = WebUtil.GetParam(context, "time", false);

            // These two params are for "scope".  These should be "ActualId" not "UID".
            string borough    = WebUtil.GetParam(context, "borough", true);
            string subborough = WebUtil.GetParam(context, "subborough", true);

            string sld = NychanisHelper.GenerateSld(indicatorId, resolution, timeId, borough, subborough);

            context.Response.ContentType = "text/xml";
            context.Response.Write(sld);
        }
Esempio n. 19
0
        public void TestBasicGet()
        {
            object indicatorId             = 10;
            NycResultsWithMetadata results =
                NychanisHelper.Query(indicatorId, NycResolutionType.Borough, NycTimeframeType.Year, 1970, 2020);

            DumpResults(results);
            Assert.AreEqual(5, results.TotalResults, "Wrong value for TotalResults.");
            Assert.AreEqual(results.TotalResults, results.Values.Count, "Number of values didn't match TotalResults.");
            Assert.AreEqual("Housing Units", results.Indicator, "Results claimed to be for the wrong indicator.");
            Assert.AreEqual(NycResolutionType.Borough.ToString(), results.Resolution, "Results claimed to be for the wrong resolution.");
            Assert.AreEqual(2009, results.MaxYear, "Results claimed to end at the wrong year.");
            Assert.AreEqual(2000, results.MinYear, "Results claimed to start at the wrong year.");
            Assert.AreEqual(7, results.Attrs.Count, "Wrong number of columns (cols = years)");
        }
Esempio n. 20
0
        public void TestGetWithYearGaps()
        {
            object indicatorId             = 1;
            NycResultsWithMetadata results =
                NychanisHelper.Query(indicatorId, NycResolutionType.Borough, NycTimeframeType.Year, 1970, 2020);

            DumpResults(results);
            Assert.AreEqual(5, results.TotalResults, "Wrong value for TotalResults.");
            Assert.AreEqual(results.TotalResults, results.Values.Count, "Number of values didn't match TotalResults.");
            Assert.AreEqual("Condominiums, Owner Occupied or For Sale", results.Indicator, "Results claimed to be for the wrong indicator.");
            Assert.AreEqual(NycResolutionType.Borough.ToString(), results.Resolution, "Results claimed to be for the wrong resolution.");
            Assert.AreEqual(2008, results.MaxYear, "Results claimed to end at the wrong year.");
            Assert.AreEqual(2002, results.MinYear, "Results claimed to start at the wrong year.");
            // There should just be the area column, then 2002, 2005, and 2008.
            Assert.AreEqual(4, results.Attrs.Count, "Wrong number of columns (cols = years)");
        }
Esempio n. 21
0
        public void TestGetIndicatorMetadata()
        {
            IList <NycIndicatorCategory> data = NychanisHelper.GetIndicatorMetadata();

            foreach (NycIndicatorCategory cat in data)
            {
                Console.WriteLine(cat);
                foreach (NycIndicatorSubCategory subCat in cat.SubCats)
                {
                    Console.WriteLine("    " + subCat);
                    DumpResults(subCat.Indicators, "       ");
                    Assert.Greater(subCat.Indicators.Count, 0, "Should have been some indicators.");
                }
                Assert.Greater(cat.SubCats.Count, 0, "Should have been some subcategories.");
            }
            Assert.AreEqual(16, data.Count, "Wrong number of categories.");
        }
Esempio n. 22
0
        public void TestMapLayersNoScope()
        {
            object indicatorId             = 201;
            NycResultsWithMetadata results = NychanisHelper.Query(indicatorId, NycResolutionType.CensusTract, NycTimeframeType.Year, 2005, 2008,
                                                                  null, null, 0, SortType.Asc, -1, -1);

            Assert.IsNotNull(results.MapInfo, "Map stuff should be populated.");
            Assert.AreEqual(results.MapInfo.Server, "http://207.245.89.220:8080/geoserver/wms", "Wrong map server URL.");
            Assert.IsNotNull(results.MapInfo.Layers, "Should have a list of layers.");
            Assert.AreEqual(4, results.MapInfo.Layers.Count, "Wrong number of layers: " + StringHelper.Join(results.MapInfo.Layers));

            Assert.AreEqual("2005", results.MapInfo.Layers[0].Name, "Wrong name for layer 0.");
            Assert.IsNull(results.MapInfo.Layers[0].Config, "Should NOT have a config for layer 0");

            Assert.AreEqual("2006", results.MapInfo.Layers[1].Name, "Wrong name for layer 1.");
            Assert.IsNotNull(results.MapInfo.Layers[1].Config, "Should have a config for layer 1");
            string sld = (string)results.MapInfo.Layers[1].Config["SLD"];

            Assert.IsNotNull(sld, "Should have an SLD for layer 1");
            Assert.AreEqual("http://localhost/pdp/handlers/NychanisSldHandler.ashx?indicator=201&resolution=CensusTract&time=201",
                            sld, "Wrong SLD URL for layer 1");
            string layerName = (string)results.MapInfo.Layers[1].Config["layers"];

            Assert.IsNotNull(layerName, "Should have a layer for layer 1");
            Assert.AreEqual("fc:census_tracts", layerName, "Wrong layer name for layer 1");

            Assert.AreEqual("2007", results.MapInfo.Layers[2].Name, "Wrong name for layer 2.");
            Assert.IsNotNull(results.MapInfo.Layers[2].Config, "Should have a config for layer 2");
            sld = (string)results.MapInfo.Layers[2].Config["SLD"];
            Assert.IsNotNull(sld, "Should have an SLD for layer 2");
            Assert.AreEqual("http://localhost/pdp/handlers/NychanisSldHandler.ashx?indicator=201&resolution=CensusTract&time=206",
                            sld, "Wrong SLD URL for layer 2");
            layerName = (string)results.MapInfo.Layers[1].Config["layers"];
            Assert.IsNotNull(layerName, "Should have a layer for layer 2");
            Assert.AreEqual("fc:census_tracts", layerName, "Wrong layer name for layer 2");

            Assert.AreEqual("2008", results.MapInfo.Layers[3].Name, "Wrong name for layer 3.");
            Assert.IsNotNull(results.MapInfo.Layers[3].Config, "Should have a config for layer 3");
            sld = (string)results.MapInfo.Layers[3].Config["SLD"];
            Assert.IsNotNull(sld, "Should have an SLD for layer 3");
            Assert.AreEqual("http://localhost/pdp/handlers/NychanisSldHandler.ashx?indicator=201&resolution=CensusTract&time=211",
                            sld, "Wrong SLD URL for layer 3");
            layerName = (string)results.MapInfo.Layers[3].Config["layers"];
            Assert.IsNotNull(layerName, "Should have a layer for layer 3");
            Assert.AreEqual("fc:census_tracts", layerName, "Wrong layer name for layer 3");
        }
Esempio n. 23
0
        public void TestMapLayersBoroughAndSBA()
        {
            object indicatorId             = 201;
            int    borough                 = 3;   // Manhattan
            int    subbourough             = 308; // Central Harlem
            NycResultsWithMetadata results = NychanisHelper.Query(indicatorId, NycResolutionType.CensusTract, NycTimeframeType.Year, 2005, 2008,
                                                                  borough, subbourough, 0, SortType.Asc, -1, -1);

            Assert.IsNotNull(results.MapInfo, "Map stuff should be populated.");
            Assert.AreEqual(results.MapInfo.Server, "http://207.245.89.220:8080/geoserver/wms", "Wrong map server URL.");
            Assert.IsNotNull(results.MapInfo.Layers, "Should have a list of layers.");
            Assert.AreEqual(4, results.MapInfo.Layers.Count, "Wrong number of layers: " + StringHelper.Join(results.MapInfo.Layers));
            string sld = (string)results.MapInfo.Layers[3].Config["SLD"];

            Assert.IsNotNull(sld, "Should have an SLD for layer 3");
            Assert.AreEqual("http://localhost/pdp/handlers/NychanisSldHandler.ashx?indicator=201&resolution=CensusTract&time=211&borough=3&subborough=308",
                            sld, "Wrong SLD URL for layer 3");
            string layerName = (string)results.MapInfo.Layers[3].Config["layers"];

            Assert.IsNotNull(layerName, "Should have a layer for layer 3");
            Assert.AreEqual("fc:census_tracts", layerName, "Wrong layer name for layer 3");
        }
Esempio n. 24
0
        public void TestPaging()
        {
            object indicatorId = 10;
            int    numPerPage  = 10;

            // Note that page numbering is 1-based.
            NycResultsWithMetadata page1 = NychanisHelper.Query(indicatorId, NycResolutionType.SubBorough, NycTimeframeType.Year, 1999, 2009, null, null, 0, SortType.Asc, numPerPage, 1);
            NycResultsWithMetadata page2 = NychanisHelper.Query(indicatorId, NycResolutionType.SubBorough, NycTimeframeType.Year, 1999, 2009, null, null, 0, SortType.Asc, numPerPage, 2);
            NycResultsWithMetadata page5 = NychanisHelper.Query(indicatorId, NycResolutionType.SubBorough, NycTimeframeType.Year, 1999, 2009, null, null, 0, SortType.Asc, numPerPage, 5);

            // Should be the same number regardless of the page, but they shouldn't be the same.

            Assert.AreEqual(numPerPage, page1.Values.Count, "Wrong number of results for page 1.");
            Assert.AreEqual(numPerPage, page2.Values.Count, "Wrong number of results for page 2.");
            Assert.AreEqual(numPerPage, page5.Values.Count, "Wrong number of results for page 5.");

            Assert.AreNotEqual(page1.Values[0][1], page2.Values[0][1], "Page 1 and 2 had the same first object.");
            Assert.AreNotEqual(page1.Values[0][1], page5.Values[0][1], "Page 1 and 50 had the same first object.");
            Assert.AreNotEqual(page2.Values[0][1], page5.Values[0][1], "Page 2 and 50 had the same first object.");
            Assert.Greater(page1.TotalResults, numPerPage, "Total results should have been higher than what is returned on page 1.");
            Assert.Greater(page2.TotalResults, numPerPage, "Total results should have been higher than what is returned on page 2.");
            Assert.Greater(page5.TotalResults, numPerPage, "Total results should have been higher than what is returned on page 50.");
        }
Esempio n. 25
0
        protected override void InternalGET(HttpContext context, HandlerTimedCache cache)
        {
            NycQueryMetadata data = NychanisHelper.GetQueryMetadata();

            context.Response.Write(WebUtil.ObjectToJson(data));
        }