JSON tree to grid view - javascript

Good day! How to parse JSON tree structure using EXTjs to bring them to the table view? Below is the structure that I want to put it to grid, how to do it? How to set up the model and storage?
[
{"WorckGroup":"3D",
"Statistics":[
{"Specialist":"V A K","SCallCount":64,"AverageDuration":0.1136067},
{"Specialist":"K T A","SCallCount":170,"AverageDuration":0.1057270},
{"Specialist":"L A V","SCallCount":71,"AverageDuration":0.4269940}]},
{"WorckGroup":"GPSK",
"Statistics":[
{"Specialist":"B A V","SCallCount":60,"AverageDuration":0.1109374},
{"Specialist":"K K A","SCallCount":17,"AverageDuration":0.1125816}]},
{"WorckGroup":"RG",
"Statistics":[
{"Specialist":"K A F","SCallCount":128,"AverageDuration":0.0624402},
{"Specialist":"O A V","SCallCount":115,"AverageDuration":0.3808017},
{"Specialist":"F E U","SCallCount":74,"AverageDuration":0.2172953}]}
]
| 3D | V A K | 64 | 0.1136067 |
| 3D | K T A | 170 | 0.1057270 |
...
| RG | F E U | 74 | 0.2172953 |

That data structure looks to be good for a tree grid.
http://docs.sencha.com/extjs/4.2.1/#!/example/build/KitchenSink/ext-theme-neptune/#tree-grid
Otherwise you could process the response in an ajax request to loop through the data and use the loadData method in a store.

Related

Dexiejs - Filtering returns single value

My dexiedb structure looks like below.
const db = new Dexie('shipment-execution');
db.version(1).stores({
root: '++id,shipmentid,stopid',
})
My IndexedDB will look like below
| id| shipmentid| stopid|
| 1 | 6000001 | 10 |
| 2 | 6000001 | 20 |
| 3 | 6000001 | 30 |
| 4 | 6000002 | 10 |
| 5 | 6000002 | 20 |
I am trying to get all the data which has shipmentid equal to 6000001. Each time it is returning only one record (the first record ).
db.root.where({shipmentid : '6000001'}).toArray().then((d)=>{
console.log(d);
})
output is only fetching the first record
| id| shipmentid| stopid|
| 1| 6000001 | 10 |
Please let me know, what I am doing wrong.

Determine if two coordinates are within desired radius

I'm working on aggregating my city's main big intersections with my city's collision data. What am trying to accomplish is to determine the number of accidents which happened in and around the intersection within a 20 meters radius.
Luckily, I'm already far off in the project and I have two tables in my database intersections and collisions
My intersections table:
--------------------------------------------
| id | city | Latitude | Longitude |
--------------------------------------------
| 1 | 1 | 34.44444 | 84.3434 |
--------------------------------------------
| 2 | 1 | 42.4666667 | 1.4666667 |
--------------------------------------------
| 3 | 1 | 32.534167 | 66.078056 |
--------------------------------------------
| 4 | 1 | 36.948889 | 66.328611 |
--------------------------------------------
| 5 | 1 | 35.088056 | 69.046389 |
--------------------------------------------
| 6 | 1 | 36.083056 | 69.0525 |
--------------------------------------------
| 7 | 1 | 31.015833 | 61.860278 |
--------------------------------------------
MY collisions table:
--------------------------------------------
| id | cause | Latitude | Longitude |
--------------------------------------------
| 1 | 1 | 44.44444 | 81.3434 |
--------------------------------------------
| 2 | 1 | 32.4666667 | 1.4666667 |
--------------------------------------------
| 3 | 1 | 42.534167 | 63.078056 |
--------------------------------------------
| 4 | 1 | 46.948889 | 62.328611 |
--------------------------------------------
| 5 | 1 | 45.088056 | 61.046389 |
--------------------------------------------
| 6 | 1 | 46.083056 | 63.0525 |
--------------------------------------------
| 7 | 1 | 41.015833 | 69.860278 |
--------------------------------------------
Note: Some fields were omitted for simplicity sake
As you can see, both tables posses latitude and longitude fields. Now to determine if intersection and collision coordinates are close, I thought of using a MySQL query that takes an id of an intersection which then queries the collisions table to get all collisions within 20 meters of the intersection.
What is this query (in MySQL or in Sequelize)?
Here's what I have now (it's in Sequelize using a MySQL database)
// api/collisions/{intersection_id}/count
exports.intersection_accident_count = (req, res) => {
intersection.findOne({where: {equipement: req.params.intersection_id}}).then(intersection => {
let intersectionLongitude = intersection.longitude;
let intersectionLatitude = intersection.latitude;
collision.count({where: {
longitude: {
$gt: intersectionLongitude
},
latitude: {
$gt: intersectionLatitude
},
}}).then(count => {
res.status(200).json({'number_of_accidents': count});
});
});
};
You should start with straightforward way:
SELECT
i.*
FROM
intersections AS i
INNER JOIN collisions AS c ON (
ST_Distance_Sphere(POINT(i.Longitude, i.Latitude), POINT(c.Longitude, c.Latitude)) < #dist
)
This should give you results, however the query will not use any indexes at all and if you have many records it would be very slow.
You should think of adding geometry data types in your table:
ALTER TABLE `collisions` ADD COLUMN `Location` POINT;
UPDATE `collisions` SET Location = POINT(Longitude, Latitude);
ALTER TABLE `intersections` ADD COLUMN `Location` POINT;
UPDATE `intersections` SET Location = POINT(Longitude, Latitude);
You can add trigger so the Location will be populated automatically when you updating Longitude/Latitude.
Then:
SELECT
i.*
FROM
intersections AS i
INNER JOIN collisions AS c ON (
ST_Distance_Sphere(i.Location, c.Location) < #dist
)
This would be a bit faster.
If you'd like to make it even faster, you can add another geometry poligon Area column into your intersection table and 'pre-build' areas (can be round for accuracy or square for speed).
After that you will be able to do something like this:
SELECT
i.*
FROM
intersections AS i
INNER JOIN collisions AS c ON (
ST_WITHIN(c.Location, i.Area)
)

Display 2D data in angular js from spring rest controller

I need to display data like below
+------+----------+----------+----------+
| Name | Subject1 | Subject2 | subject3 |
+------+----------+----------+----------+
| A | 20 | 30 | 40 |
| B | 21 | 31 | 41 |
| C | 2 | 3 | 4 |
+------+----------+----------+----------+
I used spring mvc. I created a model - Student.Java
import java.util.ArrayList;
public class Student {
ArrayList<String> markList;
public ArrayList<String> getMarkList() {
return markList;
}
public void setMarkList(ArrayList<String> markList) {
this.markList = markList;
}
}
I used ResponseBody and returned List for that method. I used ajax call and got the JSON response as below
[{"markList":["name","subject1","subject2","subject3"]}{"markList": ["A",20","30","40"]},{"students":["B",21","31","41"]},{"students":["C",2","3","4"]}]
In my Angularjs controller i just used a ajax call and assigned as below
var reponseData= reponse.data;
var studentarray;
var marklist;
for(var i=0;i<responseData.length;i++){
studentarray.push(responseData[i]);
}
for(var j=0;j<studentarray.length;j++){
marklist.push(studentarray[j].markList);
}
$scope.studentslist=marklist;
My jsp code
{{col}}
But I am not getting the desired result.Can somebody help me how to design the model and access it in js. Please help
You don't need to re-iterate an array an create a new array on the page, just directly assigns response.data to studentslist. You could just use ng-repeat to render a table on page.
<table class="table table-bordered">
<tr ng-repeat="list in studentslist">
<td ng-repeat="mark in list.markList">{{mark}}</td>
</tr>
</table>

handsontable formula returning #NEED_UPDATE

I have a handsontable, for example:
+---+------+-------+-------+
| | A | B | C |
+---+------+-------+-------+
| 1 | 10 | 20 | 30 |
+---+------+-------+-------+
| 2 | 5 |=0.5+A3|=0.5+B3|
+---+------+-------+-------+
| 3 |=A1+A2|=B1+B2 |=C1+C2 |
+---+------+-------+-------+
when the table is loaded, B2 and C2 has value of #NEED_UPDATE instead of calculation result of its formula. how to handle this issue?
Nevermind, I solved this. add afterRender callback:
afterRender: function(){
this.setDataAtCell(ROW, COL, FORMULA);
}
this will automatically update all cell to the right.

Submitting Rows of Input Fields to Server

I have an HTML table of Input elements. How do I submit just the rows with edited fields to the server?
| 1 | A | B | C | D | E |
| 2 | A | B | C | D | E |
| 3 | A | B | C | D | E |
If 2B is changed, I want to send row 2.
create dynamically the inputs, add a event listener to each one (onchange) to add the input to an array, on other event get the data of the inputs in the array, send it and clean the array

Categories

Resources