Beispiel #1
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));
        }
        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.");
        }
        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");
        }
        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).");
        }
        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.");
        }
        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.");
        }
        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");
        }
        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);
        }
        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.");
        }
Beispiel #10
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.");
        }
Beispiel #11
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).");
        }
Beispiel #12
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)");
        }
Beispiel #13
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)");
        }
Beispiel #14
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");
        }
Beispiel #15
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");
        }
Beispiel #16
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.");
        }
Beispiel #17
0
 private static void DumpResults(NycResultsWithMetadata results)
 {
     Console.WriteLine("Indicator: " + results.Indicator + ", Resolution: " + results.Resolution +
                       ", Years: " + results.MinYear + "-" + results.MaxYear);
     PropertyTests.DumpResultsWithMetadata(results);
 }