2 changed files
NumberSearch.DataAccess/Models | ||
IngestStatistics.cs | ||
NumberSearch.Mvc/Views/Ingest | ||
Index.cshtml | ||
IngestStatistics.cs
/NumberSearch.DataAccess/Models/IngestStatistics.cs+9/NumberSearch.DataAccess/Models/IngestStatistics.cs
Add comment 20 public DateTime StartDate { get; set; }
Add comment 21 public DateTime EndDate { get; set; }
Add comment 22
Add comment 23 Plus public enum IngestSource
Add comment 24 Plus {
Add comment 25 Plus DatabaseCleanup,
Add comment 26 Plus TeleMessage,
Add comment 27 Plus FirstCom,
Add comment 28 Plus BulkVS,
Add comment 29 Plus All
Add comment 30 Plus }
Add comment 31 Plus
Add comment 23 32 public static async Task<IEnumerable<IngestStatistics>> GetAllAsync(string connectionString)
Add comment 24 33 {
Add comment 25 34 using var connection = new NpgsqlConnection(connectionString);
Index.cshtml
/NumberSearch.Mvc/Views/Ingest/Index.cshtml-164+53/NumberSearch.Mvc/Views/Ingest/Index.cshtml
Add comment 9
Add comment 10 <script src="https://d3js.org/d3.v5.min.js"></script>
Add comment 11 <script type="text/javascript">
Add comment 12 Minus var margin = {
Add comment 13 Minus top: 20,
Add comment 14 Minus right: 20,
Add comment 15 Minus bottom: 30,
Add comment 16 Minus left: 50
Add comment 17 Minus },
Add comment 18 Minus width = 960 - margin.left - margin.right,
Add comment 19 Minus height = 500 - margin.top - margin.bottom;
Add comment 20 12
Add comment 21 Minus var state = 0;
Add comment 22 13
Add comment 14 Plus
Add comment 23 15 @{
Add comment 16 Plus var graphData = Model?.Where(x => x.IngestedFrom == "All").Take(31).ToArray();
Add comment 24 17 var commaString = string.Empty;
Add comment 25 Minus foreach (var ingest in Model)
Add comment 18 Plus foreach (var ingest in graphData)
Add comment 26 19 {
Add comment 27 Minus if (ingest.IngestedFrom == "All")
Add comment 28 Minus {
Add comment 29 20 commaString += $"{ingest.NumbersRetrived}, ";
Add comment 30 21 }
Add comment 31 Minus }
Add comment 32 22 @Html.Raw($"var numbersRetrivedArr = [{commaString}];");
Add comment 33 23 }
Add comment 34 24
Add comment 35 25 @{
Add comment 36 26 commaString = string.Empty;
Add comment 37 Minus foreach (var ingest in Model)
Add comment 27 Plus foreach (var ingest in graphData)
Add comment 38 28 {
Add comment 39 Minus if (ingest.IngestedFrom == "All")
Add comment 40 Minus {
Add comment 41 29 commaString += $"{ingest.IngestedNew}, ";
Add comment 42 30 }
Add comment 43 Minus }
Add comment 44 31 @Html.Raw($"var ingestedNewArr = [{commaString}];");
Add comment 45 32 }
Add comment 46 33
Add comment 47 34 @{
Add comment 48 35 commaString = string.Empty;
Add comment 49 Minus foreach (var ingest in Model)
Add comment 36 Plus foreach (var ingest in graphData)
Add comment 50 37 {
Add comment 51 Minus if (ingest.IngestedFrom == "All")
Add comment 52 Minus {
Add comment 53 38 commaString += $"{ingest.FailedToIngest}, ";
Add comment 54 39 }
Add comment 55 Minus }
Add comment 56 40 @Html.Raw($"var failedToIngestArr = [{commaString}];");
Add comment 57 41 }
Add comment 58 42
Add comment 59 43 @{
Add comment 60 44 commaString = string.Empty;
Add comment 61 Minus foreach (var ingest in Model)
Add comment 62 Minus {
Add comment 63 Minus if (ingest.IngestedFrom == "All")
Add comment 45 Plus foreach (var ingest in graphData)
Add comment 64 46 {
Add comment 65 47 commaString += $"{ingest.UpdatedExisting}, ";
Add comment 66 48 }
Add comment 67 Minus }
Add comment 68 49 @Html.Raw($"var updatedExisting = [{commaString}];");
Add comment 69 50 }
Add comment 70 51
Add comment 71 52 @{
Add comment 72 53 commaString = string.Empty;
Add comment 73 Minus foreach (var ingest in Model)
Add comment 74 Minus {
Add comment 75 Minus if (ingest.IngestedFrom == "All")
Add comment 54 Plus foreach (var ingest in graphData)
Add comment 76 55 {
Add comment 77 56 commaString += $"{ingest.Unchanged}, ";
Add comment 78 57 }
Add comment 79 Minus }
Add comment 80 58 @Html.Raw($"var unchangedArr = [{commaString}];");
Add comment 81 59 }
Add comment 82 60
Add comment 83 61 @{
Add comment 84 62 commaString = string.Empty;
Add comment 85 Minus foreach (var ingest in Model)
Add comment 86 Minus {
Add comment 87 Minus if (ingest.IngestedFrom == "All")
Add comment 63 Plus foreach (var ingest in graphData)
Add comment 88 64 {
Add comment 89 65 commaString += $"{ingest.Removed}, ";
Add comment 90 66 }
Add comment 67 Plus @Html.Raw($"var removedArr = [{commaString}];");
Add comment 68 Plus }
Add comment 69 Plus
Add comment 70 Plus @{
Add comment 71 Plus commaString = string.Empty;
Add comment 72 Plus foreach (var ingest in graphData)
Add comment 73 Plus {
Add comment 74 Plus commaString += $"\"{ingest.StartDate.ToShortDateString()}\", ";
Add comment 91 75 }
Add comment 92 Minus @Html.Raw($"var removedArr = [{commaString}];");
Add comment 76 Plus @Html.Raw($"var dateArr = [{commaString}];");
Add comment 93 77 }
Add comment 94 78
Add comment 95 79 const numIngests = Array.from({
Add comment 135 119 numIngests: numIngestsArr
Add comment 136 120 }
Add comment 137 121
Add comment 138 Minus const data = []
Add comment 139 122
Add comment 140 Minus function drawChart(chartNum) {
Add comment 141 Minus // set the dimensions and margins of the graph
Add comment 142 Minus var margin = {
Add comment 143 Minus top: 10,
Add comment 144 Minus right: 30,
Add comment 145 Minus bottom: 30,
Add comment 146 Minus left: 60
Add comment 147 Minus },
Add comment 148 Minus width = 460 - margin.left - margin.right,
Add comment 149 Minus height = 400 - margin.top - margin.bottom;
Add comment 150 Minus
Add comment 151 Minus // append the svg object to the body of the page
Add comment 152 Minus var svg = d3.select("#my_dataviz")
Add comment 153 Minus .append("svg")
Add comment 154 Minus .attr("width", width + margin.left + margin.right)
Add comment 155 Minus .attr("height", height + margin.top + margin.bottom)
Add comment 156 Minus .append("g")
Add comment 157 Minus .attr("transform",
Add comment 158 Minus "translate(" + margin.left + "," + margin.top + ")");
Add comment 159 Minus
Add comment 160 Minus //Read the data
Add comment 161 Minus //Use the margin convention practice
Add comment 162 Minus var margin = {
Add comment 163 Minus top: 50,
Add comment 164 Minus right: 50,
Add comment 165 Minus bottom: 50,
Add comment 166 Minus left: 50
Add comment 167 Minus },
Add comment 168 Minus width = window.innerWidth - margin.left - margin.right // Use the window's width
Add comment 169 Minus ,
Add comment 170 Minus height = window.innerHeight - margin.top - margin.bottom; // Use the window's height
Add comment 171 Minus
Add comment 172 Minus // The number of datapoints
Add comment 173 Minus var n = 21;
Add comment 174 Minus
Add comment 175 Minus // 5. X scale will use the index of our data
Add comment 176 Minus var xScale = d3.scaleLinear()
Add comment 177 Minus .domain([0, d3.values(youData)[1][chartNum].values.length]) // input
Add comment 178 Minus .range([0, width]); // output
Add comment 179 Minus var yMax = d3.max(d3.values(youData)[1][chartNum].values);
Add comment 180 Minus //----> 6. Y scale will use the randomly generate number <-------
Add comment 181 Minus var yScale = d3.scaleLinear()
Add comment 182 Minus .domain([0, yMax]) // input
Add comment 183 Minus .range([height, 0]); // output
Add comment 184 Minus
Add comment 185 Minus // 7. d3's line generator
Add comment 186 Minus var line = d3.line()
Add comment 187 Minus .x(function (d, i) {
Add comment 188 Minus return xScale(i);
Add comment 189 Minus }) // set the x values for the line generator
Add comment 190 Minus .y(function (d) {
Add comment 191 Minus return yScale(d.y);
Add comment 192 Minus }) // set the y values for the line generator
Add comment 193 Minus .curve(d3.curveMonotoneX) // apply smoothing to the line
Add comment 194 Minus console.log(chartNum)
Add comment 195 Minus console.log(d3.values(youData)[1][chartNum])
Add comment 196 Minus // 8. An array of objects of length N. Each object has key -> value pair, the key being "y" and the value is a random number
Add comment 197 Minus var dataset = d3.range(numbersRetrivedArr.length).map(function (d) {
Add comment 198 Minus return {
Add comment 199 Minus "y": d3.values(youData)[1][chartNum].values[d]
Add comment 200 Minus }
Add comment 201 Minus })
Add comment 202 Minus
Add comment 203 Minus // 1. Add the SVG to the page and employ #2
Add comment 204 Minus var svg = d3.select("#wolololol").append("svg")
Add comment 205 Minus .attr("id", "thisischart")
Add comment 206 Minus .attr("width", width + margin.left + margin.right)
Add comment 207 Minus .attr("height", height + margin.top + margin.bottom)
Add comment 208 Minus .append("g")
Add comment 209 Minus .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
Add comment 210 Minus
Add comment 211 Minus // 3. Call the x axis in a group tag
Add comment 212 Minus svg.append("g")
Add comment 213 Minus .attr("class", "x axis")
Add comment 214 Minus .attr("transform", "translate(0," + height + ")")
Add comment 215 Minus .call(d3.axisBottom(xScale)); // Create an axis component with d3.axisBottom
Add comment 216 Minus
Add comment 217 Minus // 4. Call the y axis in a group tag
Add comment 218 Minus svg.append("g")
Add comment 219 Minus .attr("class", "y axis")
Add comment 220 Minus .call(d3.axisLeft(yScale)); // Create an axis component with d3.axisLeft
Add comment 221 Minus
Add comment 222 Minus // 9. Append the path, bind the data, and call the line generator
Add comment 223 Minus svg.append("path")
Add comment 224 Minus .datum(dataset) // 10. Binds data to the line
Add comment 225 Minus .attr("class", "line") // Assign a class for styling
Add comment 226 Minus .attr("d", line); // 11. Calls the line generator
Add comment 227 Minus
Add comment 228 Minus // 12. Appends a circle for each datapoint
Add comment 229 Minus svg.selectAll(".dot")
Add comment 230 Minus .data(dataset)
Add comment 231 Minus .enter().append("circle") // Uses the enter().append() method
Add comment 232 Minus .attr("class", "dot") // Assign a class for styling
Add comment 233 Minus .attr("cx", function (d, i) {
Add comment 234 Minus return xScale(i)
Add comment 235 Minus })
Add comment 236 Minus .attr("cy", function (d) {
Add comment 237 Minus return yScale(d.y)
Add comment 238 Minus })
Add comment 239 Minus .attr("r", 5)
Add comment 240 Minus .on("mouseover", function (a, b, c) {
Add comment 241 Minus console.log(a)
Add comment 242 Minus this.attr('class', 'focus')
Add comment 243 Minus })
Add comment 244 Minus .on("mouseout", function () { })
Add comment 245 Minus }
Add comment 246 Minus
Add comment 247 Minus function nextChart() {
Add comment 248 Minus console.log(d3.values(youData)[1].length - 1);
Add comment 249 Minus
Add comment 250 Minus if (state = 0) {
Add comment 251 Minus drawChart(state);
Add comment 252 Minus break;
Add comment 253 Minus }
Add comment 254 Minus
Add comment 255 Minus if (state < d3.values(youData)[1].length - 1) {
Add comment 256 Minus state++;
Add comment 257 Minus } else {
Add comment 258 Minus state = 0;
Add comment 259 Minus }
Add comment 260 Minus var el = document.getElementById('thisischart');
Add comment 261 Minus console.log(el);
Add comment 262 Minus el.remove();
Add comment 263 Minus drawChart(state);
Add comment 264 Minus }
Add comment 265 123 </script>
Add comment 266 124
Add comment 267 125 <style type="text/css">
Add comment 297 155 <h1 class="display-4">Ingests</h1>
Add comment 298 156 </div>
Add comment 299 157
Add comment 300 Minus <div id="wolololol">
Add comment 301 Minus
Add comment 302 Minus </div>
Add comment 303 Minus
Add comment 304 Minus <button onclick="nextChart()">Next Chart</button>
Add comment 158 Plus <canvas id="myChart" width="400" height="200" class="pb-5"></canvas>
Add comment 305 159
Add comment 306 160 @{
Add comment 307 161 if (Model != null && Model?.Length > 0)
Add comment 373 227 }
Add comment 374 228 }
Add comment 375 229 </div>
Add comment 230 Plus
Add comment 231 Plus <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
Add comment 232 Plus <script>
Add comment 233 Plus var ctx = document.getElementById('myChart');
Add comment 234 Plus var myChart = new Chart(ctx, {
Add comment 235 Plus type: 'line',
Add comment 236 Plus data: {
Add comment 237 Plus labels: dateArr,
Add comment 238 Plus datasets: [{
Add comment 239 Plus label: 'Count of Phone Numbers Ingested',
Add comment 240 Plus data: numbersRetrivedArr,
Add comment 241 Plus backgroundColor: [
Add comment 242 Plus 'rgba(75, 192, 192, 0.2)',
Add comment 243 Plus 'rgba(153, 102, 255, 0.2)',
Add comment 244 Plus 'rgba(255, 159, 64, 0.2)'
Add comment 245 Plus ],
Add comment 246 Plus borderColor: [
Add comment 247 Plus 'rgba(75, 192, 192, 1)',
Add comment 248 Plus 'rgba(153, 102, 255, 1)',
Add comment 249 Plus 'rgba(255, 159, 64, 1)'
Add comment 250 Plus ],
Add comment 251 Plus borderWidth: 1
Add comment 252 Plus }]
Add comment 253 Plus },
Add comment 254 Plus options: {
Add comment 255 Plus scales: {
Add comment 256 Plus yAxes: [{
Add comment 257 Plus ticks: {
Add comment 258 Plus beginAtZero: false
Add comment 259 Plus }
Add comment 260 Plus }]
Add comment 261 Plus }
Add comment 262 Plus }
Add comment 263 Plus });
Add comment 264 Plus </script>