Reading from JSON files, basic calculations and writing over another JSON fileParsing JSON from file in JavaReading and storing values from JSONReading and Parsing JSON from a Game ServerCreate JSON file from WordPress ACF optionsSearch and sort customers from JSON fileParsing and saving JSON result from GoEuro APIPHP create JSON file from Twitter APIWriting CSV file from huge JSON dataReading values from a file and assigning to another classRead and write to multiple json files

SOQL: Populate a Literal List in WHERE IN Clause

How to change two letters closest to a string and one letter immediately after a string using notepad++

Recruiter wants very extensive technical details about all of my previous work

Credit cards used everywhere in Singapore or Malaysia?

Look at your watch and tell me what time is it. vs Look at your watch and tell me what time it is

Co-worker team leader wants to inject his friend's awful software into our development. What should I say to our common boss?

Why would a flight no longer considered airworthy be redirected like this?

If I can solve Sudoku can I solve Travelling Salesman Problem(TSP)? If yes, how?

My Graph Theory Students

Instead of Universal Basic Income, why not Universal Basic NEEDS?

What has been your most complicated TikZ drawing?

A sequence that has integer values for prime indexes only:

Are all passive ability checks floors for active ability checks?

Have researchers managed to "reverse time"? If so, what does that mean for physics?

What is a^b and (a&b)<<1?

Employee lack of ownership

Define, (actually define) the "stability" and "energy" of a compound

Why Choose Less Effective Armour Types?

Is it possible to upcast ritual spells?

Dice rolling probability game

Bach's Toccata and Fugue in D minor breaks the "no parallel octaves" rule?

What is the significance behind "40 days" that often appears in the Bible?

Do the common programs (for example: "ls", "cat") in Linux and BSD come from the same source code?

Identifying the interval from A♭ to D♯



Reading from JSON files, basic calculations and writing over another JSON file


Parsing JSON from file in JavaReading and storing values from JSONReading and Parsing JSON from a Game ServerCreate JSON file from WordPress ACF optionsSearch and sort customers from JSON fileParsing and saving JSON result from GoEuro APIPHP create JSON file from Twitter APIWriting CSV file from huge JSON dataReading values from a file and assigning to another classRead and write to multiple json files













0












$begingroup$


Review



Class SectorController calculates coefficients for sectors of equity exchange markets using minute data from an API. Would you be so kind and review this class, which is also connected to some other classes, some of them I will post after this review?



I have simplified and added some dummy numbers (such as 0.05, 5) to be easier for your review. If there is anything that can make this script faster, it would be great.



Script



class SectorController


/**
*
* @var a string of iextrading base URL
*/

const BASE_URL = "https://api.iextrading.com/1.0/";

/**
*
* @var a string of target path and query
*/

const TARGET_QUERY = "stock/market/batch?symbols=";


/**
*
* @var a string for backend path for every sector
*/

const EACH_SECTOR_DIR_PREFIX = "/../../dir/dir/dir/dir-";


/**
*
* @var a string for backend path for index sector
*/

const INDEX_SECTOR_DIR_PREFIX = "/../../dir/dir/dir/dir/";


/**
*
* @var a string for live data path
*/

const LIVE_DATA_DIR = "/../../../public_html/dir/dir/";

function __construct()

echo "YAAAY! " . __METHOD__ . " success 💚n";
return true;


public static function getSectors()
$baseUrl=self::BASE_URL.self::TARGET_QUERY;
$currentTime = date("Y-m-d-H-i-s");

$permission = 0755;

$indexData = array( "Overall" => array("sector_weight" => 1, "sector_coefficient" => 5,
$sectorInfos=SectorController::iexSectorParams();
foreach ($sectorInfos as $a => $sectorInfo)
$sectorUrl = $baseUrl . implode(",", array_keys($sectorInfo["selected_tickers"])) . "&types=quote&range=1m";
$rawSectorJson = file_get_contents($sectorUrl);
$rawSectorArray = json_decode($rawSectorJson, true);

// Write the raw file
$rawSectorDir = __DIR__ . self::EACH_SECTOR_DIR_PREFIX . $sectorInfo["directory"];

if (!is_dir($rawSectorDir))
mkdir($rawSectorDir, $permission, true);


$rawSectorFile = $rawSectorDir . "/" . $currentTime . ".json";
$fp = fopen($rawSectorFile, "a+");
fwrite($fp, $rawSectorJson);
fclose($fp);

// Calculate the real-time index
$indexValue = 0;
foreach ($rawSectorArray as $ticker => $tickerStats)
if (isset($sectorInfo["selected_tickers"][$ticker], $tickerStats["quote"], $tickerStats["quote"]["extendedChangePercent"], $tickerStats["quote"]["changePercent"], $tickerStats["quote"]["ytdChange"]))

$changeAmount = ($tickerStats["quote"]["extendedChangePercent"] + $tickerStats["quote"]["changePercent"] + $tickerStats["quote"]["ytdChange"])/200;
$indexValue += $sectorInfo["sector_weight"] * $sectorInfo["selected_tickers"][$ticker] * $changeAmount;



$indexData[$sectorInfo["sector"]] = array("sector_weight" => $sectorInfo["sector_weight"], "sector_coefficient" => 5,
$indexData["Overall"]["sector_value"] += $indexData[$sectorInfo["sector"]]["sector_value"];


// Calculate the index factor for better visibility between -1 and +1
$frontIndexData = array();
foreach ($indexData as $sectorName => $sectorIndexData)
$indexSign = $sectorIndexData["sector_value"];
if ($indexSign < 0)
$indexSign = - $indexSign;


$indexFactor = 1;
for ($i=0; $i <= 10; $i++)
$indexFactor = pow(10, $i);
if (($indexFactor * $indexSign) > 1)
$indexFactor = pow(10, $i - 1);
break;



$frontIndexData[$sectorName] = $sectorIndexData["sector_weight"] * $sectorIndexData["sector_coefficient"] * $sectorIndexData["sector_value"] * $indexFactor;


// Write the index file
$indexSectorDir = __DIR__ . self::INDEX_SECTOR_DIR_PREFIX;

if (!is_dir($indexSectorDir)) mkdir($indexSectorDir, $permission, true);

$indexSectorFile = $indexSectorDir . $currentTime . ".json";

$indexSectorJson = json_encode($frontIndexData, JSON_FORCE_OBJECT);
$fp = fopen($indexSectorFile, "a+");
fwrite($fp, $indexSectorJson);
fclose($fp);

$sectorDir = __DIR__ . self::LIVE_DATA_DIR;


if (!is_dir($sectorDir)) mkdir($sectorDir, $permission, true); // if data directory did not exist

// if text file did not exist
if (!file_exists($sectorDir . "text.txt"))
$handle=fopen($sectorDir . "text.txt", "wb");
fwrite($handle, "d");
fclose($handle);


$sectorCoefFile = $sectorDir . "text.txt";
copy($indexSectorFile, $sectorCoefFile);
echo "YAAAY! " . __METHOD__ . " updated sector coefficients successfully 💚!n";

return $frontIndexData;



public static function iexSectorParams()
$sectorInfos = array(
array(
"sector" => "IT",
"directory" => "information-technology",
"sector_weight" => 0.05,
"sector_coefficient" => 5,
"selected_tickers" => array(
"AAPL" => 0.05,
"AMZN" => 0.05,
"GOOGL" => 0.05,
"IBM" => 0.05
"MSFT" => 0.05
"FB" => 0.05
"NFLX" => 0.05,
"ADBE" => 0.05,
"CRM" => 0.05,
"NVDA" => 0.05,
)
),
array(
"sector" => "Telecommunication",
"directory" => "telecommunication-services",
"sector_weight" => 0.05,
"sector_coefficient" => 5,
"selected_tickers" => array(
"VZ" => 0.05,
"CSCO" => 0.05,
"CMCSA" => 0.05,
"T" => 0.05,
"CTL" => 0.05
"CHTR" => 0.05
"S" => 0.05,
"DISH" => 0.05,
"USM" => 0.05,
"VOD" => 0.05,
)
),
array(
"sector" => "Finance",
"directory" => "financial-services",
"sector_weight" => 0.05
"sector_coefficient" => 5,
"selected_tickers" => array(
"JPM" => 0.05,
"GS" => 0.05,
"V" => 0.05,
"BAC" => 0.05,
"AXP" => 0.05
"WFC" => 0.05
"USB" => 0.05,
"PNC" => 0.05,
"AMG" => 0.05,
"AIG" => 0.05,
)
),
array(
"sector" => "Energy",
"directory" => "energy",
"sector_weight" => 0.05
"sector_coefficient" => 5,
"selected_tickers" => array(
"CVX" => 0.05,
"XOM" => 0.05,
"APA" => 0.05,
"COP" => 0.05,
"BHGE" => 0.05
"VLO" => 0.05
"APC" => 0.05,
"ANDV" => 0.05,
"OXY" => 0.05,
"HAL" => 0.05,
)
),
array(
"sector" => "Industrials",
"directory" => "industrials",
"sector_weight" => 0.05,
"sector_coefficient" => 5,
"selected_tickers" => array(
"CAT" => 0.05,
"FLR" => 0.05,
"GE" => 0.05,
"JEC" => 0.05,
"JCI" => 0.05
"MAS" => 0.05
"FLS" => 0.05,
"AAL" => 0.05,
"AME" => 0.05,
"CHRW" => 0.05,
)
),
array(
"sector" => "Materials and Chemicals",
"directory" => "materials-and-chemicals",
"sector_weight" => 0.05,
"sector_coefficient" => 5,
"selected_tickers" => array(
"DWDP" => 0.05,
"APD" => 0.05,
"EMN" => 0.05,
"ECL" => 0.05,
"FMC" => 0.05
"LYB" => 0.05
"MOS" => 0.05,
"NEM" => 0.05,
"PPG" => 0.05,
"MLM" => 0.05,
)
),
array(
"sector" => "Utilities",
"directory" => "utilities",
"sector_weight" => 0.05,
"sector_coefficient" => 5,
"selected_tickers" => array(
"PPL" => 0.05,
"PCG" => 0.05,
"SO" => 0.05,
"WEC" => 0.05,
"PEG" => 0.05
"XEL" => 0.05
"D" => 0.05,
"NGG" => 0.05,
"NEE" => 0.05,
"PNW" => 0.05,
)
),
array(
"sector" => "Consumer Discretionary",
"directory" => "consumer-discretionary",
"sector_weight" => 0.05,
"sector_coefficient" => 5,
"selected_tickers" => array(
"DIS" => 0.05,
"HD" => 0.05,
"BBY" => 0.05,
"CBS" => 0.05,
"CMG" => 0.05
"MCD" => 0.05
"GPS" => 0.05,
"HOG" => 0.05,
"AZO" => 0.05,
"EXPE" => 0.05,
)
),
array(
"sector" => "Consumer Staples",
"directory" => "consumer-staples",
"sector_weight" => 0.05,
"sector_coefficient" => 5,
"selected_tickers" => array(
"PEP" => 0.05,
"PM" => 0.05,
"PG" => 0.05,
"MNST" => 0.05,
"TSN" => 0.05
"CPB" => 0.05
"HRL" => 0.05,
"SJM" => 0.05,
"CAG" => 0.05,
"KHC" => 0.05,
)
),
array(
"sector" => "Defense",
"directory" => "defense-and-aerospace",
"sector_weight" => 0.05,
"sector_coefficient" => 5,
"selected_tickers" => array(
"BA" => 0.05,
"LMT" => 0.05,
"UTX" => 0.05,
"NOC" => 0.05,
"HON" => 0.05
"RTN" => 0.05
"TXT" => 0.05,
"LLL" => 0.05,
"COL" => 0.05,
"GD" => 0.05,
)
),
array(
"sector" => "Health",
"directory" => "health-care-and-pharmaceuticals",
"sector_weight" => 0.05,
"sector_coefficient" => 5,
"selected_tickers" => array(
"UNH" => 0.05,
"JNJ" => 0.05,
"PFE" => 0.05,
"UHS" => 0.05,
"AET" => 0.05
"RMD" => 0.05
"TMO" => 0.05,
"MRK" => 0.05,
"ABT" => 0.05,
"LLY" => 0.05,
)
),


array(
"sector" => "Real Estate",
"directory" => "real-estate",
"sector_weight" => 0.05,
"sector_coefficient" => 5,
"selected_tickers" => array(
"CCI" => 0.05,
"AMT" => 0.05,
"AVB" => 0.05,
"HCP" => 0.05,
"RCL" => 0.05
"HST" => 0.05
"NCLH" => 0.05,
"HLT" => 0.05,
"ARE" => 0.05,
"AIV" => 0.05,
)
)
);
return $sectorInfos;



function __destruct()

echo "YAAAY! " . __METHOD__ . " success! 💚 n";
return true;





Output (text.txt)




"Overall":0.05,"IT":0.05,"Telecommunication":0.05,"Finance":0.05,"Energy":0.05,"Industrials":0.05,"Materials
and Chemicals":0.05,"Utilities":0.05,"Consumer
Discretionary":0.05,"Consumer
Staples":0.05,"Defense":0.05,"Health":0.05,"Real Estate":0.05











share|improve this question









$endgroup$
















    0












    $begingroup$


    Review



    Class SectorController calculates coefficients for sectors of equity exchange markets using minute data from an API. Would you be so kind and review this class, which is also connected to some other classes, some of them I will post after this review?



    I have simplified and added some dummy numbers (such as 0.05, 5) to be easier for your review. If there is anything that can make this script faster, it would be great.



    Script



    class SectorController


    /**
    *
    * @var a string of iextrading base URL
    */

    const BASE_URL = "https://api.iextrading.com/1.0/";

    /**
    *
    * @var a string of target path and query
    */

    const TARGET_QUERY = "stock/market/batch?symbols=";


    /**
    *
    * @var a string for backend path for every sector
    */

    const EACH_SECTOR_DIR_PREFIX = "/../../dir/dir/dir/dir-";


    /**
    *
    * @var a string for backend path for index sector
    */

    const INDEX_SECTOR_DIR_PREFIX = "/../../dir/dir/dir/dir/";


    /**
    *
    * @var a string for live data path
    */

    const LIVE_DATA_DIR = "/../../../public_html/dir/dir/";

    function __construct()

    echo "YAAAY! " . __METHOD__ . " success 💚n";
    return true;


    public static function getSectors()
    $baseUrl=self::BASE_URL.self::TARGET_QUERY;
    $currentTime = date("Y-m-d-H-i-s");

    $permission = 0755;

    $indexData = array( "Overall" => array("sector_weight" => 1, "sector_coefficient" => 5,
    $sectorInfos=SectorController::iexSectorParams();
    foreach ($sectorInfos as $a => $sectorInfo)
    $sectorUrl = $baseUrl . implode(",", array_keys($sectorInfo["selected_tickers"])) . "&types=quote&range=1m";
    $rawSectorJson = file_get_contents($sectorUrl);
    $rawSectorArray = json_decode($rawSectorJson, true);

    // Write the raw file
    $rawSectorDir = __DIR__ . self::EACH_SECTOR_DIR_PREFIX . $sectorInfo["directory"];

    if (!is_dir($rawSectorDir))
    mkdir($rawSectorDir, $permission, true);


    $rawSectorFile = $rawSectorDir . "/" . $currentTime . ".json";
    $fp = fopen($rawSectorFile, "a+");
    fwrite($fp, $rawSectorJson);
    fclose($fp);

    // Calculate the real-time index
    $indexValue = 0;
    foreach ($rawSectorArray as $ticker => $tickerStats)
    if (isset($sectorInfo["selected_tickers"][$ticker], $tickerStats["quote"], $tickerStats["quote"]["extendedChangePercent"], $tickerStats["quote"]["changePercent"], $tickerStats["quote"]["ytdChange"]))

    $changeAmount = ($tickerStats["quote"]["extendedChangePercent"] + $tickerStats["quote"]["changePercent"] + $tickerStats["quote"]["ytdChange"])/200;
    $indexValue += $sectorInfo["sector_weight"] * $sectorInfo["selected_tickers"][$ticker] * $changeAmount;



    $indexData[$sectorInfo["sector"]] = array("sector_weight" => $sectorInfo["sector_weight"], "sector_coefficient" => 5,
    $indexData["Overall"]["sector_value"] += $indexData[$sectorInfo["sector"]]["sector_value"];


    // Calculate the index factor for better visibility between -1 and +1
    $frontIndexData = array();
    foreach ($indexData as $sectorName => $sectorIndexData)
    $indexSign = $sectorIndexData["sector_value"];
    if ($indexSign < 0)
    $indexSign = - $indexSign;


    $indexFactor = 1;
    for ($i=0; $i <= 10; $i++)
    $indexFactor = pow(10, $i);
    if (($indexFactor * $indexSign) > 1)
    $indexFactor = pow(10, $i - 1);
    break;



    $frontIndexData[$sectorName] = $sectorIndexData["sector_weight"] * $sectorIndexData["sector_coefficient"] * $sectorIndexData["sector_value"] * $indexFactor;


    // Write the index file
    $indexSectorDir = __DIR__ . self::INDEX_SECTOR_DIR_PREFIX;

    if (!is_dir($indexSectorDir)) mkdir($indexSectorDir, $permission, true);

    $indexSectorFile = $indexSectorDir . $currentTime . ".json";

    $indexSectorJson = json_encode($frontIndexData, JSON_FORCE_OBJECT);
    $fp = fopen($indexSectorFile, "a+");
    fwrite($fp, $indexSectorJson);
    fclose($fp);

    $sectorDir = __DIR__ . self::LIVE_DATA_DIR;


    if (!is_dir($sectorDir)) mkdir($sectorDir, $permission, true); // if data directory did not exist

    // if text file did not exist
    if (!file_exists($sectorDir . "text.txt"))
    $handle=fopen($sectorDir . "text.txt", "wb");
    fwrite($handle, "d");
    fclose($handle);


    $sectorCoefFile = $sectorDir . "text.txt";
    copy($indexSectorFile, $sectorCoefFile);
    echo "YAAAY! " . __METHOD__ . " updated sector coefficients successfully 💚!n";

    return $frontIndexData;



    public static function iexSectorParams()
    $sectorInfos = array(
    array(
    "sector" => "IT",
    "directory" => "information-technology",
    "sector_weight" => 0.05,
    "sector_coefficient" => 5,
    "selected_tickers" => array(
    "AAPL" => 0.05,
    "AMZN" => 0.05,
    "GOOGL" => 0.05,
    "IBM" => 0.05
    "MSFT" => 0.05
    "FB" => 0.05
    "NFLX" => 0.05,
    "ADBE" => 0.05,
    "CRM" => 0.05,
    "NVDA" => 0.05,
    )
    ),
    array(
    "sector" => "Telecommunication",
    "directory" => "telecommunication-services",
    "sector_weight" => 0.05,
    "sector_coefficient" => 5,
    "selected_tickers" => array(
    "VZ" => 0.05,
    "CSCO" => 0.05,
    "CMCSA" => 0.05,
    "T" => 0.05,
    "CTL" => 0.05
    "CHTR" => 0.05
    "S" => 0.05,
    "DISH" => 0.05,
    "USM" => 0.05,
    "VOD" => 0.05,
    )
    ),
    array(
    "sector" => "Finance",
    "directory" => "financial-services",
    "sector_weight" => 0.05
    "sector_coefficient" => 5,
    "selected_tickers" => array(
    "JPM" => 0.05,
    "GS" => 0.05,
    "V" => 0.05,
    "BAC" => 0.05,
    "AXP" => 0.05
    "WFC" => 0.05
    "USB" => 0.05,
    "PNC" => 0.05,
    "AMG" => 0.05,
    "AIG" => 0.05,
    )
    ),
    array(
    "sector" => "Energy",
    "directory" => "energy",
    "sector_weight" => 0.05
    "sector_coefficient" => 5,
    "selected_tickers" => array(
    "CVX" => 0.05,
    "XOM" => 0.05,
    "APA" => 0.05,
    "COP" => 0.05,
    "BHGE" => 0.05
    "VLO" => 0.05
    "APC" => 0.05,
    "ANDV" => 0.05,
    "OXY" => 0.05,
    "HAL" => 0.05,
    )
    ),
    array(
    "sector" => "Industrials",
    "directory" => "industrials",
    "sector_weight" => 0.05,
    "sector_coefficient" => 5,
    "selected_tickers" => array(
    "CAT" => 0.05,
    "FLR" => 0.05,
    "GE" => 0.05,
    "JEC" => 0.05,
    "JCI" => 0.05
    "MAS" => 0.05
    "FLS" => 0.05,
    "AAL" => 0.05,
    "AME" => 0.05,
    "CHRW" => 0.05,
    )
    ),
    array(
    "sector" => "Materials and Chemicals",
    "directory" => "materials-and-chemicals",
    "sector_weight" => 0.05,
    "sector_coefficient" => 5,
    "selected_tickers" => array(
    "DWDP" => 0.05,
    "APD" => 0.05,
    "EMN" => 0.05,
    "ECL" => 0.05,
    "FMC" => 0.05
    "LYB" => 0.05
    "MOS" => 0.05,
    "NEM" => 0.05,
    "PPG" => 0.05,
    "MLM" => 0.05,
    )
    ),
    array(
    "sector" => "Utilities",
    "directory" => "utilities",
    "sector_weight" => 0.05,
    "sector_coefficient" => 5,
    "selected_tickers" => array(
    "PPL" => 0.05,
    "PCG" => 0.05,
    "SO" => 0.05,
    "WEC" => 0.05,
    "PEG" => 0.05
    "XEL" => 0.05
    "D" => 0.05,
    "NGG" => 0.05,
    "NEE" => 0.05,
    "PNW" => 0.05,
    )
    ),
    array(
    "sector" => "Consumer Discretionary",
    "directory" => "consumer-discretionary",
    "sector_weight" => 0.05,
    "sector_coefficient" => 5,
    "selected_tickers" => array(
    "DIS" => 0.05,
    "HD" => 0.05,
    "BBY" => 0.05,
    "CBS" => 0.05,
    "CMG" => 0.05
    "MCD" => 0.05
    "GPS" => 0.05,
    "HOG" => 0.05,
    "AZO" => 0.05,
    "EXPE" => 0.05,
    )
    ),
    array(
    "sector" => "Consumer Staples",
    "directory" => "consumer-staples",
    "sector_weight" => 0.05,
    "sector_coefficient" => 5,
    "selected_tickers" => array(
    "PEP" => 0.05,
    "PM" => 0.05,
    "PG" => 0.05,
    "MNST" => 0.05,
    "TSN" => 0.05
    "CPB" => 0.05
    "HRL" => 0.05,
    "SJM" => 0.05,
    "CAG" => 0.05,
    "KHC" => 0.05,
    )
    ),
    array(
    "sector" => "Defense",
    "directory" => "defense-and-aerospace",
    "sector_weight" => 0.05,
    "sector_coefficient" => 5,
    "selected_tickers" => array(
    "BA" => 0.05,
    "LMT" => 0.05,
    "UTX" => 0.05,
    "NOC" => 0.05,
    "HON" => 0.05
    "RTN" => 0.05
    "TXT" => 0.05,
    "LLL" => 0.05,
    "COL" => 0.05,
    "GD" => 0.05,
    )
    ),
    array(
    "sector" => "Health",
    "directory" => "health-care-and-pharmaceuticals",
    "sector_weight" => 0.05,
    "sector_coefficient" => 5,
    "selected_tickers" => array(
    "UNH" => 0.05,
    "JNJ" => 0.05,
    "PFE" => 0.05,
    "UHS" => 0.05,
    "AET" => 0.05
    "RMD" => 0.05
    "TMO" => 0.05,
    "MRK" => 0.05,
    "ABT" => 0.05,
    "LLY" => 0.05,
    )
    ),


    array(
    "sector" => "Real Estate",
    "directory" => "real-estate",
    "sector_weight" => 0.05,
    "sector_coefficient" => 5,
    "selected_tickers" => array(
    "CCI" => 0.05,
    "AMT" => 0.05,
    "AVB" => 0.05,
    "HCP" => 0.05,
    "RCL" => 0.05
    "HST" => 0.05
    "NCLH" => 0.05,
    "HLT" => 0.05,
    "ARE" => 0.05,
    "AIV" => 0.05,
    )
    )
    );
    return $sectorInfos;



    function __destruct()

    echo "YAAAY! " . __METHOD__ . " success! 💚 n";
    return true;





    Output (text.txt)




    "Overall":0.05,"IT":0.05,"Telecommunication":0.05,"Finance":0.05,"Energy":0.05,"Industrials":0.05,"Materials
    and Chemicals":0.05,"Utilities":0.05,"Consumer
    Discretionary":0.05,"Consumer
    Staples":0.05,"Defense":0.05,"Health":0.05,"Real Estate":0.05











    share|improve this question









    $endgroup$














      0












      0








      0





      $begingroup$


      Review



      Class SectorController calculates coefficients for sectors of equity exchange markets using minute data from an API. Would you be so kind and review this class, which is also connected to some other classes, some of them I will post after this review?



      I have simplified and added some dummy numbers (such as 0.05, 5) to be easier for your review. If there is anything that can make this script faster, it would be great.



      Script



      class SectorController


      /**
      *
      * @var a string of iextrading base URL
      */

      const BASE_URL = "https://api.iextrading.com/1.0/";

      /**
      *
      * @var a string of target path and query
      */

      const TARGET_QUERY = "stock/market/batch?symbols=";


      /**
      *
      * @var a string for backend path for every sector
      */

      const EACH_SECTOR_DIR_PREFIX = "/../../dir/dir/dir/dir-";


      /**
      *
      * @var a string for backend path for index sector
      */

      const INDEX_SECTOR_DIR_PREFIX = "/../../dir/dir/dir/dir/";


      /**
      *
      * @var a string for live data path
      */

      const LIVE_DATA_DIR = "/../../../public_html/dir/dir/";

      function __construct()

      echo "YAAAY! " . __METHOD__ . " success 💚n";
      return true;


      public static function getSectors()
      $baseUrl=self::BASE_URL.self::TARGET_QUERY;
      $currentTime = date("Y-m-d-H-i-s");

      $permission = 0755;

      $indexData = array( "Overall" => array("sector_weight" => 1, "sector_coefficient" => 5,
      $sectorInfos=SectorController::iexSectorParams();
      foreach ($sectorInfos as $a => $sectorInfo)
      $sectorUrl = $baseUrl . implode(",", array_keys($sectorInfo["selected_tickers"])) . "&types=quote&range=1m";
      $rawSectorJson = file_get_contents($sectorUrl);
      $rawSectorArray = json_decode($rawSectorJson, true);

      // Write the raw file
      $rawSectorDir = __DIR__ . self::EACH_SECTOR_DIR_PREFIX . $sectorInfo["directory"];

      if (!is_dir($rawSectorDir))
      mkdir($rawSectorDir, $permission, true);


      $rawSectorFile = $rawSectorDir . "/" . $currentTime . ".json";
      $fp = fopen($rawSectorFile, "a+");
      fwrite($fp, $rawSectorJson);
      fclose($fp);

      // Calculate the real-time index
      $indexValue = 0;
      foreach ($rawSectorArray as $ticker => $tickerStats)
      if (isset($sectorInfo["selected_tickers"][$ticker], $tickerStats["quote"], $tickerStats["quote"]["extendedChangePercent"], $tickerStats["quote"]["changePercent"], $tickerStats["quote"]["ytdChange"]))

      $changeAmount = ($tickerStats["quote"]["extendedChangePercent"] + $tickerStats["quote"]["changePercent"] + $tickerStats["quote"]["ytdChange"])/200;
      $indexValue += $sectorInfo["sector_weight"] * $sectorInfo["selected_tickers"][$ticker] * $changeAmount;



      $indexData[$sectorInfo["sector"]] = array("sector_weight" => $sectorInfo["sector_weight"], "sector_coefficient" => 5,
      $indexData["Overall"]["sector_value"] += $indexData[$sectorInfo["sector"]]["sector_value"];


      // Calculate the index factor for better visibility between -1 and +1
      $frontIndexData = array();
      foreach ($indexData as $sectorName => $sectorIndexData)
      $indexSign = $sectorIndexData["sector_value"];
      if ($indexSign < 0)
      $indexSign = - $indexSign;


      $indexFactor = 1;
      for ($i=0; $i <= 10; $i++)
      $indexFactor = pow(10, $i);
      if (($indexFactor * $indexSign) > 1)
      $indexFactor = pow(10, $i - 1);
      break;



      $frontIndexData[$sectorName] = $sectorIndexData["sector_weight"] * $sectorIndexData["sector_coefficient"] * $sectorIndexData["sector_value"] * $indexFactor;


      // Write the index file
      $indexSectorDir = __DIR__ . self::INDEX_SECTOR_DIR_PREFIX;

      if (!is_dir($indexSectorDir)) mkdir($indexSectorDir, $permission, true);

      $indexSectorFile = $indexSectorDir . $currentTime . ".json";

      $indexSectorJson = json_encode($frontIndexData, JSON_FORCE_OBJECT);
      $fp = fopen($indexSectorFile, "a+");
      fwrite($fp, $indexSectorJson);
      fclose($fp);

      $sectorDir = __DIR__ . self::LIVE_DATA_DIR;


      if (!is_dir($sectorDir)) mkdir($sectorDir, $permission, true); // if data directory did not exist

      // if text file did not exist
      if (!file_exists($sectorDir . "text.txt"))
      $handle=fopen($sectorDir . "text.txt", "wb");
      fwrite($handle, "d");
      fclose($handle);


      $sectorCoefFile = $sectorDir . "text.txt";
      copy($indexSectorFile, $sectorCoefFile);
      echo "YAAAY! " . __METHOD__ . " updated sector coefficients successfully 💚!n";

      return $frontIndexData;



      public static function iexSectorParams()
      $sectorInfos = array(
      array(
      "sector" => "IT",
      "directory" => "information-technology",
      "sector_weight" => 0.05,
      "sector_coefficient" => 5,
      "selected_tickers" => array(
      "AAPL" => 0.05,
      "AMZN" => 0.05,
      "GOOGL" => 0.05,
      "IBM" => 0.05
      "MSFT" => 0.05
      "FB" => 0.05
      "NFLX" => 0.05,
      "ADBE" => 0.05,
      "CRM" => 0.05,
      "NVDA" => 0.05,
      )
      ),
      array(
      "sector" => "Telecommunication",
      "directory" => "telecommunication-services",
      "sector_weight" => 0.05,
      "sector_coefficient" => 5,
      "selected_tickers" => array(
      "VZ" => 0.05,
      "CSCO" => 0.05,
      "CMCSA" => 0.05,
      "T" => 0.05,
      "CTL" => 0.05
      "CHTR" => 0.05
      "S" => 0.05,
      "DISH" => 0.05,
      "USM" => 0.05,
      "VOD" => 0.05,
      )
      ),
      array(
      "sector" => "Finance",
      "directory" => "financial-services",
      "sector_weight" => 0.05
      "sector_coefficient" => 5,
      "selected_tickers" => array(
      "JPM" => 0.05,
      "GS" => 0.05,
      "V" => 0.05,
      "BAC" => 0.05,
      "AXP" => 0.05
      "WFC" => 0.05
      "USB" => 0.05,
      "PNC" => 0.05,
      "AMG" => 0.05,
      "AIG" => 0.05,
      )
      ),
      array(
      "sector" => "Energy",
      "directory" => "energy",
      "sector_weight" => 0.05
      "sector_coefficient" => 5,
      "selected_tickers" => array(
      "CVX" => 0.05,
      "XOM" => 0.05,
      "APA" => 0.05,
      "COP" => 0.05,
      "BHGE" => 0.05
      "VLO" => 0.05
      "APC" => 0.05,
      "ANDV" => 0.05,
      "OXY" => 0.05,
      "HAL" => 0.05,
      )
      ),
      array(
      "sector" => "Industrials",
      "directory" => "industrials",
      "sector_weight" => 0.05,
      "sector_coefficient" => 5,
      "selected_tickers" => array(
      "CAT" => 0.05,
      "FLR" => 0.05,
      "GE" => 0.05,
      "JEC" => 0.05,
      "JCI" => 0.05
      "MAS" => 0.05
      "FLS" => 0.05,
      "AAL" => 0.05,
      "AME" => 0.05,
      "CHRW" => 0.05,
      )
      ),
      array(
      "sector" => "Materials and Chemicals",
      "directory" => "materials-and-chemicals",
      "sector_weight" => 0.05,
      "sector_coefficient" => 5,
      "selected_tickers" => array(
      "DWDP" => 0.05,
      "APD" => 0.05,
      "EMN" => 0.05,
      "ECL" => 0.05,
      "FMC" => 0.05
      "LYB" => 0.05
      "MOS" => 0.05,
      "NEM" => 0.05,
      "PPG" => 0.05,
      "MLM" => 0.05,
      )
      ),
      array(
      "sector" => "Utilities",
      "directory" => "utilities",
      "sector_weight" => 0.05,
      "sector_coefficient" => 5,
      "selected_tickers" => array(
      "PPL" => 0.05,
      "PCG" => 0.05,
      "SO" => 0.05,
      "WEC" => 0.05,
      "PEG" => 0.05
      "XEL" => 0.05
      "D" => 0.05,
      "NGG" => 0.05,
      "NEE" => 0.05,
      "PNW" => 0.05,
      )
      ),
      array(
      "sector" => "Consumer Discretionary",
      "directory" => "consumer-discretionary",
      "sector_weight" => 0.05,
      "sector_coefficient" => 5,
      "selected_tickers" => array(
      "DIS" => 0.05,
      "HD" => 0.05,
      "BBY" => 0.05,
      "CBS" => 0.05,
      "CMG" => 0.05
      "MCD" => 0.05
      "GPS" => 0.05,
      "HOG" => 0.05,
      "AZO" => 0.05,
      "EXPE" => 0.05,
      )
      ),
      array(
      "sector" => "Consumer Staples",
      "directory" => "consumer-staples",
      "sector_weight" => 0.05,
      "sector_coefficient" => 5,
      "selected_tickers" => array(
      "PEP" => 0.05,
      "PM" => 0.05,
      "PG" => 0.05,
      "MNST" => 0.05,
      "TSN" => 0.05
      "CPB" => 0.05
      "HRL" => 0.05,
      "SJM" => 0.05,
      "CAG" => 0.05,
      "KHC" => 0.05,
      )
      ),
      array(
      "sector" => "Defense",
      "directory" => "defense-and-aerospace",
      "sector_weight" => 0.05,
      "sector_coefficient" => 5,
      "selected_tickers" => array(
      "BA" => 0.05,
      "LMT" => 0.05,
      "UTX" => 0.05,
      "NOC" => 0.05,
      "HON" => 0.05
      "RTN" => 0.05
      "TXT" => 0.05,
      "LLL" => 0.05,
      "COL" => 0.05,
      "GD" => 0.05,
      )
      ),
      array(
      "sector" => "Health",
      "directory" => "health-care-and-pharmaceuticals",
      "sector_weight" => 0.05,
      "sector_coefficient" => 5,
      "selected_tickers" => array(
      "UNH" => 0.05,
      "JNJ" => 0.05,
      "PFE" => 0.05,
      "UHS" => 0.05,
      "AET" => 0.05
      "RMD" => 0.05
      "TMO" => 0.05,
      "MRK" => 0.05,
      "ABT" => 0.05,
      "LLY" => 0.05,
      )
      ),


      array(
      "sector" => "Real Estate",
      "directory" => "real-estate",
      "sector_weight" => 0.05,
      "sector_coefficient" => 5,
      "selected_tickers" => array(
      "CCI" => 0.05,
      "AMT" => 0.05,
      "AVB" => 0.05,
      "HCP" => 0.05,
      "RCL" => 0.05
      "HST" => 0.05
      "NCLH" => 0.05,
      "HLT" => 0.05,
      "ARE" => 0.05,
      "AIV" => 0.05,
      )
      )
      );
      return $sectorInfos;



      function __destruct()

      echo "YAAAY! " . __METHOD__ . " success! 💚 n";
      return true;





      Output (text.txt)




      "Overall":0.05,"IT":0.05,"Telecommunication":0.05,"Finance":0.05,"Energy":0.05,"Industrials":0.05,"Materials
      and Chemicals":0.05,"Utilities":0.05,"Consumer
      Discretionary":0.05,"Consumer
      Staples":0.05,"Defense":0.05,"Health":0.05,"Real Estate":0.05











      share|improve this question









      $endgroup$




      Review



      Class SectorController calculates coefficients for sectors of equity exchange markets using minute data from an API. Would you be so kind and review this class, which is also connected to some other classes, some of them I will post after this review?



      I have simplified and added some dummy numbers (such as 0.05, 5) to be easier for your review. If there is anything that can make this script faster, it would be great.



      Script



      class SectorController


      /**
      *
      * @var a string of iextrading base URL
      */

      const BASE_URL = "https://api.iextrading.com/1.0/";

      /**
      *
      * @var a string of target path and query
      */

      const TARGET_QUERY = "stock/market/batch?symbols=";


      /**
      *
      * @var a string for backend path for every sector
      */

      const EACH_SECTOR_DIR_PREFIX = "/../../dir/dir/dir/dir-";


      /**
      *
      * @var a string for backend path for index sector
      */

      const INDEX_SECTOR_DIR_PREFIX = "/../../dir/dir/dir/dir/";


      /**
      *
      * @var a string for live data path
      */

      const LIVE_DATA_DIR = "/../../../public_html/dir/dir/";

      function __construct()

      echo "YAAAY! " . __METHOD__ . " success 💚n";
      return true;


      public static function getSectors()
      $baseUrl=self::BASE_URL.self::TARGET_QUERY;
      $currentTime = date("Y-m-d-H-i-s");

      $permission = 0755;

      $indexData = array( "Overall" => array("sector_weight" => 1, "sector_coefficient" => 5,
      $sectorInfos=SectorController::iexSectorParams();
      foreach ($sectorInfos as $a => $sectorInfo)
      $sectorUrl = $baseUrl . implode(",", array_keys($sectorInfo["selected_tickers"])) . "&types=quote&range=1m";
      $rawSectorJson = file_get_contents($sectorUrl);
      $rawSectorArray = json_decode($rawSectorJson, true);

      // Write the raw file
      $rawSectorDir = __DIR__ . self::EACH_SECTOR_DIR_PREFIX . $sectorInfo["directory"];

      if (!is_dir($rawSectorDir))
      mkdir($rawSectorDir, $permission, true);


      $rawSectorFile = $rawSectorDir . "/" . $currentTime . ".json";
      $fp = fopen($rawSectorFile, "a+");
      fwrite($fp, $rawSectorJson);
      fclose($fp);

      // Calculate the real-time index
      $indexValue = 0;
      foreach ($rawSectorArray as $ticker => $tickerStats)
      if (isset($sectorInfo["selected_tickers"][$ticker], $tickerStats["quote"], $tickerStats["quote"]["extendedChangePercent"], $tickerStats["quote"]["changePercent"], $tickerStats["quote"]["ytdChange"]))

      $changeAmount = ($tickerStats["quote"]["extendedChangePercent"] + $tickerStats["quote"]["changePercent"] + $tickerStats["quote"]["ytdChange"])/200;
      $indexValue += $sectorInfo["sector_weight"] * $sectorInfo["selected_tickers"][$ticker] * $changeAmount;



      $indexData[$sectorInfo["sector"]] = array("sector_weight" => $sectorInfo["sector_weight"], "sector_coefficient" => 5,
      $indexData["Overall"]["sector_value"] += $indexData[$sectorInfo["sector"]]["sector_value"];


      // Calculate the index factor for better visibility between -1 and +1
      $frontIndexData = array();
      foreach ($indexData as $sectorName => $sectorIndexData)
      $indexSign = $sectorIndexData["sector_value"];
      if ($indexSign < 0)
      $indexSign = - $indexSign;


      $indexFactor = 1;
      for ($i=0; $i <= 10; $i++)
      $indexFactor = pow(10, $i);
      if (($indexFactor * $indexSign) > 1)
      $indexFactor = pow(10, $i - 1);
      break;



      $frontIndexData[$sectorName] = $sectorIndexData["sector_weight"] * $sectorIndexData["sector_coefficient"] * $sectorIndexData["sector_value"] * $indexFactor;


      // Write the index file
      $indexSectorDir = __DIR__ . self::INDEX_SECTOR_DIR_PREFIX;

      if (!is_dir($indexSectorDir)) mkdir($indexSectorDir, $permission, true);

      $indexSectorFile = $indexSectorDir . $currentTime . ".json";

      $indexSectorJson = json_encode($frontIndexData, JSON_FORCE_OBJECT);
      $fp = fopen($indexSectorFile, "a+");
      fwrite($fp, $indexSectorJson);
      fclose($fp);

      $sectorDir = __DIR__ . self::LIVE_DATA_DIR;


      if (!is_dir($sectorDir)) mkdir($sectorDir, $permission, true); // if data directory did not exist

      // if text file did not exist
      if (!file_exists($sectorDir . "text.txt"))
      $handle=fopen($sectorDir . "text.txt", "wb");
      fwrite($handle, "d");
      fclose($handle);


      $sectorCoefFile = $sectorDir . "text.txt";
      copy($indexSectorFile, $sectorCoefFile);
      echo "YAAAY! " . __METHOD__ . " updated sector coefficients successfully 💚!n";

      return $frontIndexData;



      public static function iexSectorParams()
      $sectorInfos = array(
      array(
      "sector" => "IT",
      "directory" => "information-technology",
      "sector_weight" => 0.05,
      "sector_coefficient" => 5,
      "selected_tickers" => array(
      "AAPL" => 0.05,
      "AMZN" => 0.05,
      "GOOGL" => 0.05,
      "IBM" => 0.05
      "MSFT" => 0.05
      "FB" => 0.05
      "NFLX" => 0.05,
      "ADBE" => 0.05,
      "CRM" => 0.05,
      "NVDA" => 0.05,
      )
      ),
      array(
      "sector" => "Telecommunication",
      "directory" => "telecommunication-services",
      "sector_weight" => 0.05,
      "sector_coefficient" => 5,
      "selected_tickers" => array(
      "VZ" => 0.05,
      "CSCO" => 0.05,
      "CMCSA" => 0.05,
      "T" => 0.05,
      "CTL" => 0.05
      "CHTR" => 0.05
      "S" => 0.05,
      "DISH" => 0.05,
      "USM" => 0.05,
      "VOD" => 0.05,
      )
      ),
      array(
      "sector" => "Finance",
      "directory" => "financial-services",
      "sector_weight" => 0.05
      "sector_coefficient" => 5,
      "selected_tickers" => array(
      "JPM" => 0.05,
      "GS" => 0.05,
      "V" => 0.05,
      "BAC" => 0.05,
      "AXP" => 0.05
      "WFC" => 0.05
      "USB" => 0.05,
      "PNC" => 0.05,
      "AMG" => 0.05,
      "AIG" => 0.05,
      )
      ),
      array(
      "sector" => "Energy",
      "directory" => "energy",
      "sector_weight" => 0.05
      "sector_coefficient" => 5,
      "selected_tickers" => array(
      "CVX" => 0.05,
      "XOM" => 0.05,
      "APA" => 0.05,
      "COP" => 0.05,
      "BHGE" => 0.05
      "VLO" => 0.05
      "APC" => 0.05,
      "ANDV" => 0.05,
      "OXY" => 0.05,
      "HAL" => 0.05,
      )
      ),
      array(
      "sector" => "Industrials",
      "directory" => "industrials",
      "sector_weight" => 0.05,
      "sector_coefficient" => 5,
      "selected_tickers" => array(
      "CAT" => 0.05,
      "FLR" => 0.05,
      "GE" => 0.05,
      "JEC" => 0.05,
      "JCI" => 0.05
      "MAS" => 0.05
      "FLS" => 0.05,
      "AAL" => 0.05,
      "AME" => 0.05,
      "CHRW" => 0.05,
      )
      ),
      array(
      "sector" => "Materials and Chemicals",
      "directory" => "materials-and-chemicals",
      "sector_weight" => 0.05,
      "sector_coefficient" => 5,
      "selected_tickers" => array(
      "DWDP" => 0.05,
      "APD" => 0.05,
      "EMN" => 0.05,
      "ECL" => 0.05,
      "FMC" => 0.05
      "LYB" => 0.05
      "MOS" => 0.05,
      "NEM" => 0.05,
      "PPG" => 0.05,
      "MLM" => 0.05,
      )
      ),
      array(
      "sector" => "Utilities",
      "directory" => "utilities",
      "sector_weight" => 0.05,
      "sector_coefficient" => 5,
      "selected_tickers" => array(
      "PPL" => 0.05,
      "PCG" => 0.05,
      "SO" => 0.05,
      "WEC" => 0.05,
      "PEG" => 0.05
      "XEL" => 0.05
      "D" => 0.05,
      "NGG" => 0.05,
      "NEE" => 0.05,
      "PNW" => 0.05,
      )
      ),
      array(
      "sector" => "Consumer Discretionary",
      "directory" => "consumer-discretionary",
      "sector_weight" => 0.05,
      "sector_coefficient" => 5,
      "selected_tickers" => array(
      "DIS" => 0.05,
      "HD" => 0.05,
      "BBY" => 0.05,
      "CBS" => 0.05,
      "CMG" => 0.05
      "MCD" => 0.05
      "GPS" => 0.05,
      "HOG" => 0.05,
      "AZO" => 0.05,
      "EXPE" => 0.05,
      )
      ),
      array(
      "sector" => "Consumer Staples",
      "directory" => "consumer-staples",
      "sector_weight" => 0.05,
      "sector_coefficient" => 5,
      "selected_tickers" => array(
      "PEP" => 0.05,
      "PM" => 0.05,
      "PG" => 0.05,
      "MNST" => 0.05,
      "TSN" => 0.05
      "CPB" => 0.05
      "HRL" => 0.05,
      "SJM" => 0.05,
      "CAG" => 0.05,
      "KHC" => 0.05,
      )
      ),
      array(
      "sector" => "Defense",
      "directory" => "defense-and-aerospace",
      "sector_weight" => 0.05,
      "sector_coefficient" => 5,
      "selected_tickers" => array(
      "BA" => 0.05,
      "LMT" => 0.05,
      "UTX" => 0.05,
      "NOC" => 0.05,
      "HON" => 0.05
      "RTN" => 0.05
      "TXT" => 0.05,
      "LLL" => 0.05,
      "COL" => 0.05,
      "GD" => 0.05,
      )
      ),
      array(
      "sector" => "Health",
      "directory" => "health-care-and-pharmaceuticals",
      "sector_weight" => 0.05,
      "sector_coefficient" => 5,
      "selected_tickers" => array(
      "UNH" => 0.05,
      "JNJ" => 0.05,
      "PFE" => 0.05,
      "UHS" => 0.05,
      "AET" => 0.05
      "RMD" => 0.05
      "TMO" => 0.05,
      "MRK" => 0.05,
      "ABT" => 0.05,
      "LLY" => 0.05,
      )
      ),


      array(
      "sector" => "Real Estate",
      "directory" => "real-estate",
      "sector_weight" => 0.05,
      "sector_coefficient" => 5,
      "selected_tickers" => array(
      "CCI" => 0.05,
      "AMT" => 0.05,
      "AVB" => 0.05,
      "HCP" => 0.05,
      "RCL" => 0.05
      "HST" => 0.05
      "NCLH" => 0.05,
      "HLT" => 0.05,
      "ARE" => 0.05,
      "AIV" => 0.05,
      )
      )
      );
      return $sectorInfos;



      function __destruct()

      echo "YAAAY! " . __METHOD__ . " success! 💚 n";
      return true;





      Output (text.txt)




      "Overall":0.05,"IT":0.05,"Telecommunication":0.05,"Finance":0.05,"Energy":0.05,"Industrials":0.05,"Materials
      and Chemicals":0.05,"Utilities":0.05,"Consumer
      Discretionary":0.05,"Consumer
      Staples":0.05,"Defense":0.05,"Health":0.05,"Real Estate":0.05








      php json api






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 3 hours ago









      EmmaEmma

      164112




      164112




















          0






          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215541%2freading-from-json-files-basic-calculations-and-writing-over-another-json-file%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215541%2freading-from-json-files-basic-calculations-and-writing-over-another-json-file%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          瀋陽號驅逐艦 目录 接收與服役 配置反潛直升機 武進三型性能升級 歷史 除役 參考資料 外部連結 导航菜单Taiwan Air Power海疆老兵-陽字號驅逐艦沿革World Navies Today: Taiwan (Republic of China)DD-839 USS POWER

          波兰旗帜列表 目录 国旗 军旗 其他制服部门旗帜 特别国家机构船只 参考文献 外部链接 导航菜单Polskie flagi, chorągwie, bandery... [波兰旗帜、条幅、船旗等]原始内容Ustawa z dnia 31 stycznia 1980 r. o godle, barwach i hymnie Rzeczypospolitej Polskiej oraz o pieczęciach państwowychZarządzenie Ministra Obrony Narodowej z dnia 14 grudnia 2005 r. zmieniające zarządzenie w sprawie szczegółowych zasad używania znaków Sił Zbrojnych Rzeczypospolitej Polskiej oraz ustalenia innych znaków używanych w Siłach Zbrojnych Rzeczypospolitej PolskiejZarządzenie Ministra Obrony Narodowej z dnia 29 stycznia 1996 r. w sprawie szczegółowych zasad używania znaków Sił Zbrojnych Rzeczypospolitej Polskiej oraz ustalenia innych znaków używanych w Siłach Zbrojnych Rzeczypospolitej PolskiejUstawa z dnia 19 lutego 1993 r. o znakach Sił Zbrojnych Rzeczypospolitej PolskiejHistoria Marynarki Wojennej RP [波兰海军史]Rozporządzenie Ministra Spraw Wewnętrznych i Administracji z dnia 12 kwietnia 2002 r. w sprawie wzoru flagi oraz oznakowania jednostek pływających i statków powietrznych Straży GranicznejRozporządzenie Ministra Spraw Wewnętrznych i Administracji z dnia 18 kwietnia 2005 r. w sprawie wzoru flagi oraz oznakowania jednostek pływających i statków powietrznych PolicjiRozporządzenie Ministra Infrastruktury z dnia 21 października 2005 r. w sprawie wzorów flag dla statków morskich na oznaczenie pełnionej specjalnej służby państwowej oraz okoliczności i warunków ich podnoszenia波兰旗帜波兰

          Indenting and Dedenting ASP code with Python