Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON: Add ability to manipulate data before processing #669

Open
contactashish13 opened this issue Mar 23, 2020 · 2 comments
Open

JSON: Add ability to manipulate data before processing #669

contactashish13 opened this issue Mar 23, 2020 · 2 comments
Labels
enhancement Request to improve or optimize an existing feature or functionality in the project

Comments

@contactashish13
Copy link
Contributor

contactashish13 commented Mar 23, 2020

ref https://secure.helpscout.net/conversation/1114000866/220789/

URL: https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=MSFT&apikey=demo

Final json data:

{
    "Meta Data": {
        "1. Information": "Daily Prices (open, high, low, close) and Volumes",
        "2. Symbol": "MSFT",
        "3. Last Refreshed": "2020-03-20",
        "4. Output Size": "Compact",
        "5. Time Zone": "US/Eastern"
    },
    "Time Series (Daily)": {
        "2020-03-20": {
            "1. open": "146.0000",
            "2. high": "147.1000",
            "3. low": "135.8600",
            "4. close": "137.3500",
            "5. volume": "84866215"
        },
        "2020-03-19": {
            "1. open": "142.7700",
            "2. high": "150.1500",
            "3. low": "139.0000",
            "4. close": "142.7100",
            "5. volume": "85922661"
        },
    }
}

This does not generate the candlestick chart as the date is outside the root viz. Time Series (Daily). The solution is to be able to add the date to the root.

@contactashish13 contactashish13 added the enhancement Request to improve or optimize an existing feature or functionality in the project label Mar 23, 2020
@contactashish13
Copy link
Contributor Author

PR #670 addresses this issue.

Specifically for the URL https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=MSFT&apikey=demo use the filter as below

add_filter( 'visualizer_json_massage_data', function( $data, $url ) {
	if ( $url === 'https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=MSFT&apikey=demo' ) {
		$new_data = $data;
		// add 'date' to each element of the root as the first value.
		foreach ( $new_data['Time Series (Daily)'] as $date => &$date_array ) {
			$new_date_array = array();
			$new_date_array[ 'date' ] = $date;
			$date_array = array_merge( $new_date_array, $date_array );
		}
		$data = $new_data;
	}
	return $data;
}, 10, 2 );

@TheActivist
Copy link

Added the above filter to my functions.php file, but dates still aren't showing up in the root. Just getting the same five data series (open, high, low, close, volume).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Request to improve or optimize an existing feature or functionality in the project
Projects
None yet
Development

No branches or pull requests

2 participants