increase by 50 all numbers of lines with "y" coordinate - algorithm

I need help. The problem: how to change all specific coordinate values by any number. Like multiplying all values of Y coordinates here by 3 or decreasing all X values by 55.
There is notepad file format with many many lines in it. Tbh thats a hideout file from path of exile game. I want to edit some objects there, so i need to manage coordinate values somehow. The reason why i want it - to share with PoE community some hideout files, but i need to move objects in it to make everything looking good.
I am have no clue how to solve it. I hope to find some wise person here <3
Example:
"Arched Gateway": {
"hash": 3294752266,
"x": 309,
"y": 237,
"r": 1756,
"fv": 0
},
"Arched Gateway": {
"hash": 3294752266,
"x": 305,
"y": 259,
"r": 4586,
"fv": 0
},
"Arched Gateway": {
"hash": 3294752266,
"x": 261,
"y": 302,
"r": 11101,
"fv": 0
},
I want to find out the wat to solve it not manually. Like function in any app or site which can change only Y coordinate values.

You can write a JSONata expression to transform your data, see https://try.jsonata.org/.
But first, you need to fix your data as it's not a valid JSON, because of duplicate key 'Arched Gateway'.
If you modify your input like this for example:
{
"ArchedGateways": [{
"hash": 3294752266,
"x": 309,
"y": 237,
"r": 1756,
"fv": 0
},
{
"hash": 3294752266,
"x": 305,
"y": 259,
"r": 4586,
"fv": 0
},
{
"hash": 3294752266,
"x": 261,
"y": 302,
"r": 11101,
"fv": 0
}
]
}
this JSONata expression would do:
ArchedGateways.{
'hash': hash,
'x': x - 55,
'y': y * 3,
'r': r,
'fv': fv
}

Related

I can't walk around the scene in VR with Aframe

I am new with aframe. I don't know if it's a problem or if aframe works like this by default.
When I try to walk in the VR with my mobile phone it doesn't work, but if I walk using AR it works.
Could you tell me if aframe works like this or is it something I'm doing wrong.
Thank you so much.
This is my code
import React from 'react';
import './styles/VirtualReality.css';
import scene from '../assets/scenes/scenario.gltf';
export default function VirtualReality() {
return (
<React.Fragment>
<a-scene vr-mode-ui="enabled: true; cardboardModeEnabled: true;">
<a-asset>
<a-asset-item
id="data"
src='[{"x": 1, "y": 8, "z": 0, "size": 1, "color": "#ff0000"},
{"x": -2, "y": 3, "z": 1, "size": 1.5, "color": "#00ff00"},
{"x": -1, "y": 3, "z": 2, "size": 1, "color": "#0000ff"},
{"x": 2, "y": 7, "z": 7, "size": 1.5, "color": "#0000ff"},
{"x": 1, "y": 6, "z": 3, "size": 1, "color": "#4CC3D9"}]'
></a-asset-item>
</a-asset>
<a-sky gltf-model={scene} color="#ECECEC"></a-sky>
<a-entity
charts="type: bar; dataPoints: #data; axis_length: 12; axis_negative: false; axis_grid: true"
scale="0.15 0.15 0.15"
position="-6 1 -10"
></a-entity>
</a-scene>
</React.Fragment>
);
}
I am using react. And in the scene I am using the default camera.
I tried to walk in VR using aframe, but it didn't work, it just stays in a fixed position, although I can look around. I thought in VR you could walk around just like you do in AR mode.

How to do multiple rotations without losing a degree of freedom?

I'm trying to display multiple "3d lines" imported from an XML file. I simply need to draw simple rectangular boxes using the provided parameters (5 x 5 x "length"), move it at the right position and rotate it using the provided rotations (in degree) - the expected result is multiple shapes starting at the provided position with their length continuing in an orientation that match the provided rotation.
For some shapes, two of the rotation axes are doing the exact same thing - this appear to be a gimbal lock issue (probably amplified because most of the rotations here are at 90 degrees).
I searched and tried multiple solutions for hours, notably using a 4x4 matrix instead of my initial implementation using geometry.rotateX/rotateY/rotateZ. Unfortunately, I'm unable to find a working solution... I found people mentioning quaternions, but I'm not quite sure how to apply this to my current use case...
I'm sure there is a (relatively) easy solution for my issue, but right now, I'm unable to find it... I'm open to any way of doing it, as long as it can be done with the input I have...
Can anyone push me in the right direction?
Thank you so much for your help.
For reference, I'm currently using r124. Here's a simplified example of my parsed input :
var lines = [
{
"length": "150",
"position": {
"x": "100",
"y": "-10",
"z": "1800"
},
"rotation": {
"x": "90",
"y": "0",
"z": "0"
}
},
{
"length": "325",
"position": {
"x": "100",
"y": "-10",
"z": "1800"
},
"rotation": {
"x": "-90",
"y": "-90",
"z": "-90"
}
},
{
"length": "55",
"position": {
"x": "100",
"y": "-10",
"z": "1800"
},
"rotation": {
"x": "0",
"y": "0",
"z": "-90"
}
}
]

Algorithm to regroup geographic points

I'm creating an app using a map and I have to place points on it. The problem is that when the points are nearby, the user can't see the difference. So, I need to regroup the points.
I receive JSONs like that:
[{"id": "1", "x": 253, "y": 144},
{"id": "2", "x": 142, "y": 355},
{"id": "3", "x": 175, "y": 330},
{"id": "4", "x": 140, "y": 5},
{"id": "5", "x": 307, "y": 306},
{"id": "6", "x": 233, "y": 304},
{"id": "7", "x": 212, "y": 163},
{"id": "8", "x": 202, "y": 163},
{"id": "9", "x": 204, "y": 171}]
And i need to regroup point with 20px difference in biggest point with coord of the average of all other points.
It's deal a JSON like that:
[{"id": ["1"], "x": 253, "y": 144},
{"id": ["2"], "x": 142, "y": 355},
{"id": ["3"], "x": 175, "y": 330},
{"id": ["4"], "x": 140, "y": 5},
{"id": ["5"], "x": 307, "y": 306},
{"id": ["6"], "x": 233, "y": 304},
{"id": ["7","8","9"], "x": 206, "y": 165}]
I just need an algorithm to help me to build my own code.
Thank you for all help you can give to me.
Euclidian distance is the shortest path between two points and calculated as
sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2))
Just iterate through your list of points from the top to the bottom and if the Euclidean distance between any two points is less than 20, remove the second point or group it with the first one, so you won't have to process it again. You can then calculate the average location of that group if you want to.

"Creating Apps in Kivy" openweathermap API Key Error

That's my first stackoverflow question.
I started with kivy and bought the book "Crating Apps in Kivy" from Dusty Phillips and all went well till he got to the openweatherapp chapter. (Which after a search other users had problems too...)
There you use the Openweather API to search for a location with a button and it should print the results in a list.
It's not the original code anymore. Others pointed out that the Link to the website changed, you have to use the API key. Of course I linked it correctly, I just typed "myAPIKey" here so it's not accesssable. The JSOn File on the bottom is what the site prints!
Also, the book formated cities in found location like that: d['name], d['sys']['country'] which I guess was also wrong, maybe the site changed here too?
My problem is that the UrlRequest from kivy doesn't seem to load anything. Or the iteration in found location is wrong, I don't know. It always says "KeyError: city" And I guess it's because it doesn't read it correctly at all. I tried a different approach with the python class requests - and it works perfectly fine! But I still want to know why this solution doesn't work.
My Questions: Where is my error with the json iteration? I have really problems with understanding because I'm also new to python.
Also: Why is request in the methode head? Where is it used?
Here the code from the book (I hope everything is typed correctly. If there is still an error with variables please point it out but I typed the code multiple times - my problem will probably be somewhere else...):
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
from kivy.network.urlrequest import UrlRequest
import json
class AddLocationForm(BoxLayout):
search_input = ObjectProperty()
search_results = ObjectProperty()
def search_location(self):
search_template = "http://api.openweathermap.org/data/2.5/forecast/daily?APPID=myAPIKey=" + "{}"
search_url = search_template.format(self.search_input.text)
request = UrlRequest(search_url, self.found_location)
def found_location(self, request, data):
data = json.loads(data.decode()) if not isinstance(data, dict) else data
cities = ["{} ({})".format(d["city"]["name"], d["city"]["country"])for d in data["list"]]
self.search_results.item_strings = cities
KV File:
AddLocationForm:
<AddLocationForm>:
orientation: "vertical"
search_input: search_box
search_results: search_results_list
BoxLayout:
height: "40dp"
size_hint_y: None
TextInput:
id: search_box
size_hint_x: 50
Button:
text: "Search"
size_hint_x: 25
on_press: root.search_location()
Button:
text: "Current Location"
size_hint_x: 25
ListView:
id: search_results_list
item_strings: []
JSON File:
{
"city": {
"id": 2761369,
"name": "Vienna",
"coord": {
"lon": 16.37208,
"lat": 48.208488
},
"country": "AT",
"population": 0
},
"cod": "200",
"message": 0.0098,
"cnt": 7,
"list": [{
"dt": 1476439200,
"temp": {
"day": 285.58,
"min": 283.71,
"max": 285.58,
"night": 283.71,
"eve": 285.43,
"morn": 285.58
},
"pressure": 985.46,
"humidity": 73,
"weather": [{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01d"
}],
"speed": 7.16,
"deg": 154,
"clouds": 0
}, {
"dt": 1476525600,
"temp": {
"day": 287.33,
"min": 282.7,
"max": 291.08,
"night": 285.72,
"eve": 291.01,
"morn": 283.35
},
"pressure": 983.21,
"humidity": 71,
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10d"
}],
"speed": 4.51,
"deg": 150,
"clouds": 32,
"rain": 0.23
}, {
"dt": 1476612000,
"temp": {
"day": 286.88,
"min": 283.94,
"max": 287.15,
"night": 283.94,
"eve": 286.44,
"morn": 286.26
},
"pressure": 989.94,
"humidity": 98,
"weather": [{
"id": 501,
"main": "Rain",
"description": "moderate rain",
"icon": "10d"
}],
"speed": 4.36,
"deg": 315,
"clouds": 92,
"rain": 5.51
}, {
"dt": 1476698400,
"temp": {
"day": 287.39,
"min": 283.49,
"max": 287.39,
"night": 284.89,
"eve": 285.05,
"morn": 283.49
},
"pressure": 984.76,
"humidity": 0,
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10d"
}],
"speed": 1.64,
"deg": 132,
"clouds": 69,
"rain": 1.55
}, {
"dt": 1476784800,
"temp": {
"day": 285.91,
"min": 283.52,
"max": 285.91,
"night": 283.52,
"eve": 284.45,
"morn": 284.18
},
"pressure": 982.64,
"humidity": 0,
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10d"
}],
"speed": 3.23,
"deg": 137,
"clouds": 81,
"rain": 2.4
}, {
"dt": 1476871200,
"temp": {
"day": 283.71,
"min": 282.37,
"max": 283.71,
"night": 282.37,
"eve": 282.52,
"morn": 282.59
},
"pressure": 978.26,
"humidity": 0,
"weather": [{
"id": 502,
"main": "Rain",
"description": "heavy intensity rain",
"icon": "10d"
}],
"speed": 2.68,
"deg": 128,
"clouds": 96,
"rain": 14.37
}, {
"dt": 1476957600,
"temp": {
"day": 286.52,
"min": 282.13,
"max": 286.52,
"night": 282.13,
"eve": 282.72,
"morn": 282.19
},
"pressure": 975.05,
"humidity": 0,
"weather": [{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10d"
}],
"speed": 1.47,
"deg": 173,
"clouds": 13,
"rain": 2.83
}]
}
Btw, it's not a duplicate from how do i use json api in my kivy program becaue it didn't really help... The code doesn't work anymore because the API changed.
(If anyone finds this question and is looking for a working URL reader, here is my code. Don't forget to import requests)
def search_location(self):
#Get URL From Weather API + Input
search_template = "http://api.openweathermap.org/data/2.5/forecast/daily?APPID='enteryourweatherAPIKeyhere'&q=" + "{}"
search_url = search_template.format(self.search_input.text)
#Reads the Website and saves it in a string
urlresults = (requests.get(search_url)).text
#Converts Json to Python Dictionary
urlresults = json.loads(urlresults)
cities = ["{} ({})".format(urlresults["city"]["name"], urlresults["city"]["country"])]
Go to this page:
http://openweathermap.org/faq#error401
the API now requires a key. After registering on openweathermap, a key will be mailed to you. Replace the current URL with the one given in the mail.
This worked for me.

Getting rendered date range from axis with NVD3

I'm using NVD3 to display of a number of line charts and would like to be able to get the min and max values of the xAxis currently displayed. In this case the xAxis shows time values.
When toggling the visibility of lines in the chart, by clicking the legend label, the date range is changed. I've added an event handler to listen to legendClicks but how do I get my hands on the newly rendered date range?
I ended up using a custom function to find the min/max values of the x axis when clicking the legend. I wrapped the function within a $timeout in order to wait for the digest cycle to be completed to get the proper value, ie:
legend: {
dispatch: {
legendClick: function(e) {
$timeout(function(){
getMinMax();
}, 0);
}
}
},
The getMinMax function is a quick and dirty one and may most likely be done in a more elegantly manner, however it does its job:
var getMinMax = function(){
var maxVal, minVal = null;
for(var i=0;i<$scope.data.length;i++) {
// Only displayed should be considered
if (!$scope.data[i].disabled) {
var tempMinVal = d3.max($scope.data[i].values, function(d) { return d.x;} );
var tempMaxVal = d3.min($scope.data[i].values, function(d) { return d.x;} );
minVal = (!minVal || tempMinVal < minVal) ? tempMinVal : minVal;
maxVal = (!maxVal || tempMaxVal > maxVal) ? tempMaxVal : maxVal;
}
}
return [minVal, maxVal];
};
Will get the min and max from the data in this format:
[
{
"key": "AA",
"values": [
{
"x": 1440712800000,
"y": "6",
"series": 0
},
{
"x": 1440712800000,
"y": "6",
"series": 0
}
]
},
{
"key": "BB",
"values": [
{
"x": 1441144800000,
"y": "3",
"series": 1
},
{
"x": 1443045600000,
"y": "3",
"series": 1
},
{
"x": 1453244400000,
"y": "3",
"series": 1
},
{
"x": 1454022000000,
"y": "3",
"series": 1
}
]
},
{
"key": "CC",
"values": [
{
"x": 1442872800000,
"y": "5",
"series": 2
},
{
"x": 1442872800000,
"y": "5",
"series": 2
}
]
},
{
"key": "DD",
"values": [
{
"x": 1443650400000,
"y": "1",
"series": 3
},
{
"x": 1443650400000,
"y": "1",
"series": 3
}
]
},
{
"key": "EE",
"values": [
{
"x": 1444773600000,
"y": "9",
"series": 4
},
{
"x": 1446073200000,
"y": "9",
"series": 4
}
]
}
]
As I reached this far the client changed mind and didn't want the functionality that required this solution. Hope it may be of use for someone else.

Resources