<commit_before>// Copyright 2016 Esri.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an 
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific 
// language governing permissions and limitations under the License.

using Android.App;
using Android.OS;
using Android.Views;
using Android.Widget;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Tasks;
using Esri.ArcGISRuntime.Tasks.Geoprocessing;
using Esri.ArcGISRuntime.UI.Controls;
using System;
using System.Threading.Tasks;

namespace ArcGISRuntime.Samples.AnalyzeHotspots
{
    [Activity]
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "Analyze hotspots",
        "Geoprocessing",
        "This sample demonstrates how to execute the GeoprocessingTask asynchronously to calculate a hotspot analysis based on the frequency of 911 calls. It calculates the frequency of these calls within a given study area during a specified constrained time period set between 1/1/1998 and 5/31/1998.",
        "To run the hotspot analysis, select a data range and click on the 'Run analysis' button. Note the larger the date range, the longer it may take for the task to run and send back the results.")]
    public class AnalyzeHotspots : Activity
    {

        // Create and hold reference to the used MapView
        private MapView _myMapView = new MapView();

        // Progress bar to show when the geoprocessing task is working
        private ProgressBar _myProgressBar;

        // Edit text to define the start date for the date range
        private EditText _myEditText_StartDate;

        // Edit text to define the end date for the date range
        private EditText _myEditText_EndDate;

        // Url for the geoprocessing service
        private const string _hotspotUrl =
            "https://sampleserver6.arcgisonline.com/arcgis/rest/services/911CallsHotspot/GPServer/911%20Calls%20Hotspot";

        // The geoprocessing task for hot spot analysis 
        private GeoprocessingTask _hotspotTask;

        // The job that handles the communication between the application and the geoprocessing task
        private GeoprocessingJob _hotspotJob;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Title = "Analyze Hotspots";

            // Create the UI, setup the control references and execute initialization 
            CreateLayout();
            Initialize();
        }

        private async void Initialize()
        {
            // Create a map with a topographic basemap
            Map myMap = new Map(Basemap.CreateTopographic());

            // Create a new geoprocessing task
            _hotspotTask = await GeoprocessingTask.CreateAsync(new Uri(_hotspotUrl));

            // Assign the map to the MapView
            _myMapView.Map = myMap;
        }

        private async void OnRunAnalysisClicked(object sender, EventArgs e)
        {
            // Clear any existing results
            _myMapView.Map.OperationalLayers.Clear();

            // Show busy activity indication
            _myProgressBar.Visibility = ViewStates.Visible;

            // Get the 'from' and 'to' dates from the date edit text's for the geoprocessing analysis
            DateTime myFromDate = Convert.ToDateTime(_myEditText_StartDate.Text);
            DateTime myToDate = Convert.ToDateTime(_myEditText_EndDate.Text);

            // The end date must be at least one day after the start date
            if (myToDate <= myFromDate.AddDays(1))
            {
                // Show error message
                AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
                alertBuilder.SetTitle("Invalid date range");
                alertBuilder.SetMessage("Please select valid time range.There has to be at least one day in between To and From dates.");
                alertBuilder.Show();

                // Remove the busy activity indication
                _myProgressBar.Visibility = ViewStates.Invisible;
                return;
            }

            // Create the parameters that are passed to the used geoprocessing task
            GeoprocessingParameters myHotspotParameters = new GeoprocessingParameters(GeoprocessingExecutionType.AsynchronousSubmit);

            // Construct the date query
            string myQueryString = $"(\"DATE\" > date '{myFromDate:yyyy-MM-dd} 00:00:00' AND \"DATE\" < date '{myToDate:yyyy-MM-dd} 00:00:00')";

            // Add the query that contains the date range used in the analysis
            myHotspotParameters.Inputs.Add("Query", new GeoprocessingString(myQueryString));

            // Create job that handles the communication between the application and the geoprocessing task
            _hotspotJob = _hotspotTask.CreateJob(myHotspotParameters);
            try
            {
                // Execute the geoprocessing analysis and wait for the results
                GeoprocessingResult myAnalysisResult = await _hotspotJob.GetResultAsync();

                // Add results to a map using map server from a geoprocessing task
                // Load to get access to full extent
                await myAnalysisResult.MapImageLayer.LoadAsync();

                // Add the analysis layer to the map view
                _myMapView.Map.OperationalLayers.Add(myAnalysisResult.MapImageLayer);

                // Zoom to the results
                await _myMapView.SetViewpointAsync(new Viewpoint(myAnalysisResult.MapImageLayer.FullExtent));
            }
            catch (TaskCanceledException)
            {
                // This is thrown if the task is canceled. Ignore.
            }
            catch (Exception ex)
            {
                // Display error messages if the geoprocessing task fails
                if (_hotspotJob.Status == JobStatus.Failed && _hotspotJob.Error != null)
                {
                    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
                    alertBuilder.SetTitle("Geoprocessing error");
                    alertBuilder.SetMessage("Executing geoprocessing failed. " + _hotspotJob.Error.Message);
                    alertBuilder.Show();
                }
                else
                {
                    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
                    alertBuilder.SetTitle("Sample error");
                    alertBuilder.SetMessage("An error occurred. " + ex.ToString());
                    alertBuilder.Show();
                }
            }
            finally
            {
                // Remove the busy activity indication
                _myProgressBar.Visibility = ViewStates.Invisible;
            }
        }

        private void CreateLayout()
        {
            // Create a new vertical layout for the app
            LinearLayout layout = new LinearLayout(this) { Orientation = Orientation.Vertical };

            // Create a horizontal sub layout for the start date
            LinearLayout subLayout1 = new LinearLayout(this) { Orientation = Orientation.Horizontal };

            // Label for the start date
            TextView textview_Label1 = new TextView(this)
            {
                Text = "Start Date:"
            };
            subLayout1.AddView(textview_Label1);

            // Edit text for the start date (user can change if desired)
            _myEditText_StartDate = new EditText(this)
            {
                Text = "1/01/98"
            };
            subLayout1.AddView(_myEditText_StartDate);

            // Add the start date information to the general layout
            layout.AddView(subLayout1);

            // Create a horizontal sub layout for the end date
            LinearLayout subLayout2 = new LinearLayout(this) { Orientation = Orientation.Horizontal };

            // Label for the end date
            TextView textview_Label2 = new TextView(this)
            {
                Text = "End Date:"
            };
            subLayout2.AddView(textview_Label2);

            // Edit text for the end date (user can change if desired)
            _myEditText_EndDate = new EditText(this)
            {
                Text = "1/31/98"
            };
            subLayout2.AddView(_myEditText_EndDate);

            // Add the start date information to the general layout
            layout.AddView(subLayout2);

            // Add a button to the run the hot spot analysis; wire up the click event as well 
            Button mapsButton = new Button(this)
            {
                Text = "Run Analysis"
            };
            mapsButton.Click += OnRunAnalysisClicked;
            layout.AddView(mapsButton);

            // Add the progress bar to indicate the geoprocessing task is running; make invisible by default
            _myProgressBar = new ProgressBar(this)
            {
                Indeterminate = true,
                Visibility = ViewStates.Invisible
            };
            layout.AddView(_myProgressBar);

            // Add the map view to the layout
            layout.AddView(_myMapView);

            // Show the layout in the app
            SetContentView(layout);
        }

    }
}<commit_msg>Handle malformed input Analyze Hotspots Android<commit_after>// Copyright 2016 Esri.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an 
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific 
// language governing permissions and limitations under the License.

using Android.App;
using Android.OS;
using Android.Views;
using Android.Widget;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Tasks;
using Esri.ArcGISRuntime.Tasks.Geoprocessing;
using Esri.ArcGISRuntime.UI.Controls;
using System;
using System.Threading.Tasks;

namespace ArcGISRuntime.Samples.AnalyzeHotspots
{
    [Activity]
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "Analyze hotspots",
        "Geoprocessing",
        "This sample demonstrates how to execute the GeoprocessingTask asynchronously to calculate a hotspot analysis based on the frequency of 911 calls. It calculates the frequency of these calls within a given study area during a specified constrained time period set between 1/1/1998 and 5/31/1998.",
        "To run the hotspot analysis, select a data range and click on the 'Run analysis' button. Note the larger the date range, the longer it may take for the task to run and send back the results.")]
    public class AnalyzeHotspots : Activity
    {

        // Create and hold reference to the used MapView
        private MapView _myMapView = new MapView();

        // Progress bar to show when the geoprocessing task is working
        private ProgressBar _myProgressBar;

        // Edit text to define the start date for the date range
        private EditText _myEditText_StartDate;

        // Edit text to define the end date for the date range
        private EditText _myEditText_EndDate;

        // Url for the geoprocessing service
        private const string _hotspotUrl =
            "https://sampleserver6.arcgisonline.com/arcgis/rest/services/911CallsHotspot/GPServer/911%20Calls%20Hotspot";

        // The geoprocessing task for hot spot analysis 
        private GeoprocessingTask _hotspotTask;

        // The job that handles the communication between the application and the geoprocessing task
        private GeoprocessingJob _hotspotJob;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Title = "Analyze Hotspots";

            // Create the UI, setup the control references and execute initialization 
            CreateLayout();
            Initialize();
        }

        private async void Initialize()
        {
            // Create a map with a topographic basemap
            Map myMap = new Map(Basemap.CreateTopographic());

            // Create a new geoprocessing task
            _hotspotTask = await GeoprocessingTask.CreateAsync(new Uri(_hotspotUrl));

            // Assign the map to the MapView
            _myMapView.Map = myMap;
        }

        private async void OnRunAnalysisClicked(object sender, EventArgs e)
        {
            // Get the 'from' and 'to' dates from the date edit text's for the geoprocessing analysis
            DateTime myFromDate;
            DateTime myToDate;

            try
            {
                myFromDate = Convert.ToDateTime(_myEditText_StartDate.Text);
                myToDate = Convert.ToDateTime(_myEditText_EndDate.Text);
            }
            catch (Exception exception)
            {
                // Show error message and quit
                new AlertDialog.Builder(this).SetMessage(exception.Message).Show();
                return;
            }

            // Clear any existing results
            _myMapView.Map.OperationalLayers.Clear();

            // Show busy activity indication
            _myProgressBar.Visibility = ViewStates.Visible;

            // The end date must be at least one day after the start date
            if (myToDate <= myFromDate.AddDays(1))
            {
                // Show error message
                AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
                alertBuilder.SetTitle("Invalid date range");
                alertBuilder.SetMessage("Please select valid time range.There has to be at least one day in between To and From dates.");
                alertBuilder.Show();

                // Remove the busy activity indication
                _myProgressBar.Visibility = ViewStates.Invisible;
                return;
            }

            // Create the parameters that are passed to the used geoprocessing task
            GeoprocessingParameters myHotspotParameters = new GeoprocessingParameters(GeoprocessingExecutionType.AsynchronousSubmit);

            // Construct the date query
            string myQueryString = $"(\"DATE\" > date '{myFromDate:yyyy-MM-dd} 00:00:00' AND \"DATE\" < date '{myToDate:yyyy-MM-dd} 00:00:00')";

            // Add the query that contains the date range used in the analysis
            myHotspotParameters.Inputs.Add("Query", new GeoprocessingString(myQueryString));

            // Create job that handles the communication between the application and the geoprocessing task
            _hotspotJob = _hotspotTask.CreateJob(myHotspotParameters);
            try
            {
                // Execute the geoprocessing analysis and wait for the results
                GeoprocessingResult myAnalysisResult = await _hotspotJob.GetResultAsync();

                // Add results to a map using map server from a geoprocessing task
                // Load to get access to full extent
                await myAnalysisResult.MapImageLayer.LoadAsync();

                // Add the analysis layer to the map view
                _myMapView.Map.OperationalLayers.Add(myAnalysisResult.MapImageLayer);

                // Zoom to the results
                await _myMapView.SetViewpointAsync(new Viewpoint(myAnalysisResult.MapImageLayer.FullExtent));
            }
            catch (TaskCanceledException)
            {
                // This is thrown if the task is canceled. Ignore.
            }
            catch (Exception ex)
            {
                // Display error messages if the geoprocessing task fails
                if (_hotspotJob.Status == JobStatus.Failed && _hotspotJob.Error != null)
                {
                    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
                    alertBuilder.SetTitle("Geoprocessing error");
                    alertBuilder.SetMessage("Executing geoprocessing failed. " + _hotspotJob.Error.Message);
                    alertBuilder.Show();
                }
                else
                {
                    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
                    alertBuilder.SetTitle("Sample error");
                    alertBuilder.SetMessage("An error occurred. " + ex.ToString());
                    alertBuilder.Show();
                }
            }
            finally
            {
                // Remove the busy activity indication
                _myProgressBar.Visibility = ViewStates.Invisible;
            }
        }

        private void CreateLayout()
        {
            // Create a new vertical layout for the app
            LinearLayout layout = new LinearLayout(this) { Orientation = Orientation.Vertical };

            // Create a horizontal sub layout for the start date
            LinearLayout subLayout1 = new LinearLayout(this) { Orientation = Orientation.Horizontal };

            // Label for the start date
            TextView textview_Label1 = new TextView(this)
            {
                Text = "Start Date:"
            };
            subLayout1.AddView(textview_Label1);

            // Edit text for the start date (user can change if desired)
            _myEditText_StartDate = new EditText(this)
            {
                Text = "1/01/98"
            };
            subLayout1.AddView(_myEditText_StartDate);

            // Add the start date information to the general layout
            layout.AddView(subLayout1);

            // Create a horizontal sub layout for the end date
            LinearLayout subLayout2 = new LinearLayout(this) { Orientation = Orientation.Horizontal };

            // Label for the end date
            TextView textview_Label2 = new TextView(this)
            {
                Text = "End Date:"
            };
            subLayout2.AddView(textview_Label2);

            // Edit text for the end date (user can change if desired)
            _myEditText_EndDate = new EditText(this)
            {
                Text = "1/31/98"
            };
            subLayout2.AddView(_myEditText_EndDate);

            // Add the start date information to the general layout
            layout.AddView(subLayout2);

            // Add a button to the run the hot spot analysis; wire up the click event as well 
            Button mapsButton = new Button(this)
            {
                Text = "Run Analysis"
            };
            mapsButton.Click += OnRunAnalysisClicked;
            layout.AddView(mapsButton);

            // Add the progress bar to indicate the geoprocessing task is running; make invisible by default
            _myProgressBar = new ProgressBar(this)
            {
                Indeterminate = true,
                Visibility = ViewStates.Invisible
            };
            layout.AddView(_myProgressBar);

            // Add the map view to the layout
            layout.AddView(_myMapView);

            // Show the layout in the app
            SetContentView(layout);
        }

    }
}
{'fraction_non_alphanumeric': 0.06633124550775234, 'fraction_numerical': 0.007187596262449944, 'mean_word_length': 1.9274120829576196, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6206598', 'n_tokens_mistral': 4933, 'n_tokens_neox': 4548, 'n_words': 1599}