Jump to content

NotionCommotion

Members
  • Content Count

    2,076
  • Joined

  • Last visited

  • Days Won

    9

NotionCommotion last won the day on July 2 2019

NotionCommotion had the most liked content!

Community Reputation

30 Good

About NotionCommotion

  • Rank
    Prolific Member

Contact Methods

  • Website URL
    http://

Profile Information

  • Gender
    Not Telling

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Are you assuming starting with the $keys and $arrayValues in my original post? $arr1 = array_fill_keys($keys, []); echo(json_encode($arr1).PHP_EOL); $arr2 = array_fill_keys($keys, $arrayValues); echo(json_encode($arr2).PHP_EOL); $values = array_map(function($values) use($keys, $arr1, $arr2) { //$arr=array_combine($arr1, $values); //Array to string conversion //$arr=array_combine($arr2, $values); //Array to string conversion $arr=array_combine($keys, $values); return $arr; }, $arrayValues); echo(json_encode($values).PHP_EOL); { "time": [], "system1_typeA": [], "system2_typeA": [], "system1_typeB": [], "system3_typeC": [], "system2_typeB": [], "system1_typeC": [] } { "time": [["2020-06-28 08:46:34", 1.71, 6.29, 6.32, 5.55, 1.25, 8.81], ["2020-06-28 08:47:45", 1.88, 8.57, 8.62, 9.98, 8.33, 8.89], ["2020-06-28 08:48:10", 5.75, 4.36, 3.54, 7.93, 8.13, 1.43], ["2020-06-28 08:49:15", 7.14, 9.54, 5.39, 4.58, 5.77, 4.72], ["2020-06-28 08:50:00", 9.42, 7.44, 1.47, 1.87, 1.23, 4.79]], "system1_typeA": [["2020-06-28 08:46:34", 1.71, 6.29, 6.32, 5.55, 1.25, 8.81], ["2020-06-28 08:47:45", 1.88, 8.57, 8.62, 9.98, 8.33, 8.89], ["2020-06-28 08:48:10", 5.75, 4.36, 3.54, 7.93, 8.13, 1.43], ["2020-06-28 08:49:15", 7.14, 9.54, 5.39, 4.58, 5.77, 4.72], ["2020-06-28 08:50:00", 9.42, 7.44, 1.47, 1.87, 1.23, 4.79]], "system2_typeA": [["2020-06-28 08:46:34", 1.71, 6.29, 6.32, 5.55, 1.25, 8.81], ["2020-06-28 08:47:45", 1.88, 8.57, 8.62, 9.98, 8.33, 8.89], ["2020-06-28 08:48:10", 5.75, 4.36, 3.54, 7.93, 8.13, 1.43], ["2020-06-28 08:49:15", 7.14, 9.54, 5.39, 4.58, 5.77, 4.72], ["2020-06-28 08:50:00", 9.42, 7.44, 1.47, 1.87, 1.23, 4.79]], "system1_typeB": [["2020-06-28 08:46:34", 1.71, 6.29, 6.32, 5.55, 1.25, 8.81], ["2020-06-28 08:47:45", 1.88, 8.57, 8.62, 9.98, 8.33, 8.89], ["2020-06-28 08:48:10", 5.75, 4.36, 3.54, 7.93, 8.13, 1.43], ["2020-06-28 08:49:15", 7.14, 9.54, 5.39, 4.58, 5.77, 4.72], ["2020-06-28 08:50:00", 9.42, 7.44, 1.47, 1.87, 1.23, 4.79]], "system3_typeC": [["2020-06-28 08:46:34", 1.71, 6.29, 6.32, 5.55, 1.25, 8.81], ["2020-06-28 08:47:45", 1.88, 8.57, 8.62, 9.98, 8.33, 8.89], ["2020-06-28 08:48:10", 5.75, 4.36, 3.54, 7.93, 8.13, 1.43], ["2020-06-28 08:49:15", 7.14, 9.54, 5.39, 4.58, 5.77, 4.72], ["2020-06-28 08:50:00", 9.42, 7.44, 1.47, 1.87, 1.23, 4.79]], "system2_typeB": [["2020-06-28 08:46:34", 1.71, 6.29, 6.32, 5.55, 1.25, 8.81], ["2020-06-28 08:47:45", 1.88, 8.57, 8.62, 9.98, 8.33, 8.89], ["2020-06-28 08:48:10", 5.75, 4.36, 3.54, 7.93, 8.13, 1.43], ["2020-06-28 08:49:15", 7.14, 9.54, 5.39, 4.58, 5.77, 4.72], ["2020-06-28 08:50:00", 9.42, 7.44, 1.47, 1.87, 1.23, 4.79]], "system1_typeC": [["2020-06-28 08:46:34", 1.71, 6.29, 6.32, 5.55, 1.25, 8.81], ["2020-06-28 08:47:45", 1.88, 8.57, 8.62, 9.98, 8.33, 8.89], ["2020-06-28 08:48:10", 5.75, 4.36, 3.54, 7.93, 8.13, 1.43], ["2020-06-28 08:49:15", 7.14, 9.54, 5.39, 4.58, 5.77, 4.72], ["2020-06-28 08:50:00", 9.42, 7.44, 1.47, 1.87, 1.23, 4.79]] } [{ "time": "2020-06-28 08:46:34", "system1_typeA": 1.71, "system2_typeA": 6.29, "system1_typeB": 6.32, "system3_typeC": 5.55, "system2_typeB": 1.25, "system1_typeC": 8.81 }, { "time": "2020-06-28 08:47:45", "system1_typeA": 1.88, "system2_typeA": 8.57, "system1_typeB": 8.62, "system3_typeC": 9.98, "system2_typeB": 8.33, "system1_typeC": 8.89 }, { "time": "2020-06-28 08:48:10", "system1_typeA": 5.75, "system2_typeA": 4.36, "system1_typeB": 3.54, "system3_typeC": 7.93, "system2_typeB": 8.13, "system1_typeC": 1.43 }, { "time": "2020-06-28 08:49:15", "system1_typeA": 7.14, "system2_typeA": 9.54, "system1_typeB": 5.39, "system3_typeC": 4.58, "system2_typeB": 5.77, "system1_typeC": 4.72 }, { "time": "2020-06-28 08:50:00", "system1_typeA": 9.42, "system2_typeA": 7.44, "system1_typeB": 1.47, "system3_typeC": 1.87, "system2_typeB": 1.23, "system1_typeC": 4.79 } ]
  2. Are you sure you are configured to display errors? Consider adding the following at the top of the page. error_reporting(E_ALL); ini_set('display_startup_errors', 1); ini_set('display_errors', 1); You also have calls to a bunch of functions which are not declared in your script. Are they being imported elsewhere? When I get stuck, I put little traps in the code (either echo, exit, or syslog) to pinpoint where the error is.
  3. Is array_map fed the keys and not the arrayValues? $map = array_map(function($v) { return explode('_',$v); }, $keys); Is array_fill_keys being passed an array for the second argument? Maybe another small (or big) hint?
  4. I have a sequential multidimensional array with many outer rows where all the inner arrays have the same number of elements as another sequential array which represents metadata of the first array's inner arrrays. $keys: ["time","system1_typeA","system2_typeA","system1_typeB","system3_typeC","system2_typeB","system1_typeC"] $arrayValues: [ ["2020-06-27 07:40:06",2.16,9.25,9.44,7.76,5.43,1.12], ["2020-06-27 07:40:23",2.66,8.93,4.31,6.59,8.44,3.42], ["2020-06-27 07:41:24",8.71,2.78,8.92,6.58,3.65,4.38], ["2020-06-27 07:41:58",1.86,6.36,2.65,3.99,7.25,3.32], ["2020-06-27 07:42:33",8.71,3.66,8.82,8.54,8.22,4.51] ] My desired output is: { "time": ["2020-06-27 07:40:06", "2020-06-27 07:40:23", "2020-06-27 07:41:24", "2020-06-27 07:41:58", "2020-06-27 07:42:33"], "system1": { "typeA": [2.16, 2.66, 8.71, 1.86, 8.71], "typeB": [9.44, 4.31, 8.92, 2.65, 8.82], "typeC": [1.12, 3.42, 4.38, 3.32, 4.51] }, "system2": { "typeA": [9.25, 8.93, 2.78, 6.36, 3.66], "typeB": [5.43, 8.44, 3.65, 7.25, 8.22] }, "system3": { "typeC": [7.76, 6.59, 6.58, 3.99, 8.54] } } Is there much faster way to do so than the following? I would like to use a built in function like array_combine() if possible, but grouping by system and type creates an issue. function transform(array $keys, array $arrayValues):array { $map=[]; foreach ($keys as $key) { $map[] = explode('_',$key); } $count=count($keys); $newValues=[]; foreach ($arrayValues as $i=>$arrayValue) { $newValues['time'][]=$arrayValue[0]; for ($i = 1; $i < $count; $i++) { $newValues[$map[$i][0]][$map[$i][1]][]=$arrayValue[$i]; } } return $newValues; }
  5. Thanks kicken, Yes, I see why addValue() might take a little time. I know performance optimization is often foolhardy, but think this is a good time to do so. Regarding the my responder question, I definitely don't need to spend any more time dwelling on it and just pick one, and will likely go with the one you suggested.
  6. Thanks kicken, Well, that is significant. ColumnData was applied on the short loop so there were few of them which contained large arrays? I would not expect significant difference in time. Guess that is why testing is always good! I know I am a little off topic, but still hope to get your thoughts. Say I had a class RawData which was injected with either a stream or some data array, and needed the ability to export the data in several different formatted versions. Would you any of the following approaches or some other approach? $rawData=new RawData($stream); $outputV1 = $rawData->createOutput(new OneOfServeralOutputFormatters()); $outputV2 = (new OneOfServeralOutputFormatters($rawData))->createOutput(); $outputV3 = (new OneOfServeralOutputFormatters())->createOutput($rawData);
  7. The approach to select a server file will be completely different. One possible strategy would be to do something like the following. Make a GET request to /files which returns [{"id": 123, "name": "some_file.txt"}, {"id": 321, "name": "some_other_file.txt"}, ...]. User selects a file and store the value on the client. If you are using XMLHttpRequest, it will be easier since it just be stored in the DOM, however, other options will work and maybe just delete it every time the page is accessed so you don't send old files. When the user sends the message off, include the ID with the data.
  8. There isn't a single desired output, and sometimes it will be fairly similar to the received data but must often it will be like the following: $series = [ new Series(new Point(51), new Aggregator('mean'), new DataValues([4.3527550826446255, 4.472219604166665, 4.332343173277662, ..., 4.272219604166665)])), new Series(new Point(55), new Aggregator('mean'), new DataValues([5.3527550826446255, 5.472219604166665, 5.332343173277662, ..., 5.272219604166665)])), new Series(new Point(56), new Aggregator('max'), new DataValues([0.6175362252066116, 0.609555860166668, 0.604520167014615, ..., 0.619555604166668)])) ]; $timeValues=new TimeValues(["2020-06-13T14:02:02Z","2020-06-13T14:02:12Z","2020-06-23T14:02:22Z", ..., "2020-06-23T14:02:22Z"]); $seriesCollection = new SeriesCollection($timeValues, ...$series); To be flexible, will likely just drop the raw data in some class: class RawDataCollection { public function __construct(string $name, array $columns, array $values) { // } } Not really sure whether best or whether it even matters to have some method to create the desired output: class RawDataCollection { public function createDataCollection(TransformerInterface $transformer):DataCollectionInterface { } } class SeriesCollectionTransfomer implements TransformerInterface { // } or do something like: class SeriesCollection { public function __construct(RawDataCollection $rawData) { // } } Was I correct in my observation that iterating over a large loop multiple times is often more efficient that iterating over it only once but then iterating over some smaller loop?
  9. I have an application which takes some time and would like to take steps to improve execution speed. Sample data is provided as JSON and is as follows where the values array has few columns and many rows. My desired outcome is three PHP objects for mean_P51, mean_P55, and max_P56 which all have a reference to the time array as well as their own values array. { "name": "L2", "columns": ["time", "mean_P51", "mean_P55", "max_P56"], "values": [ ["2020-06-13T14:02:02Z", 4.3527550826446255, 5.668302919254657, 0.6175362252066116], ["2020-06-13T14:02:12Z", 4.472219604166665, 5.493282520833331, 0.6095558604166668], ["2020-06-23T14:02:22Z", 4.332343173277662, 5.477678517745302, 0.6014520167014615], ... ["2020-06-23T14:02:22Z", 4.272219604166665, 5.468302919254657, 0.6195558604166668] ] } Originally, I thought that it would be more efficient to iterate over the big values array once and on each iteration process each column (I envision myself walking one mile and snapping my fingers three times each foot, or walking three miles and snapping my fingers once every foot). What I witness, however, is it is faster to iterate over the big values array multiple times to generate each object, and I've done a few simple tests comparing iterating big loops within little loops to little loops within big loops, and get similar results. I guess this makes sense I am not really stopping when I snap my fingers and if I did walking three miles would likely be quicker. Is this expected behavior? If there is too much data, I've needed to use a JSON stream parser and either a generator or iterator. I haven't tested it yet, but expect a generator would be more efficient than an iterator and using PHP's built-in json_decode() and an array would be more efficient than either a generator or iterator. Think I need to test this hypothesis or is it likely correct? Any other general strategies one should take when working with large datasets? Thanks
  10. You can redirect using PHP with header("Location: you_disired_url.bla"); or with JavaScript after getting your response. Make sure you understand between server side and client side.
  11. While relative paths certainly work, they are often more trouble than they are worth. If you don't want to hard code them but still want to be flexible, consider using a PHP variable to define the base to relative path and use it in your URLs.
  12. Thanks kicken, Both of your comments helped me. Never realized the implications of the composer.lock file until now, and will defiantly keep it under version control. Regarding the FK error, you were right and it turned out to be utf versus utf8mb4.
  13. Yes, I spent some time but there are 376 tables to sort through. I would rather get to some usable state and migrate the applicable data. PS. My hack solution didn't quite get me there as there as expected many missing classes.
  14. I just updated a site as follows: cd /var/www/concrete5 composer update Among other changes, the following were made (more on this later): - Updating concrete5/core (8.5.2 => 8.5.4): Downloading (100%) - Updating doctrine/collections (1.6.4 => 1.6.5): Downloading (100%) - Updating doctrine/lexer (1.2.0 => 1.2.1): Downloading (100%) - Updating doctrine/inflector (1.3.1 => 1.4.3): Downloading (100%) - Updating doctrine/cache (1.10.0 => 1.10.1): Downloading (100%) - Updating doctrine/annotations (1.10.2 => 1.10.3): Downloading (100%) - Updating doctrine/common (2.12.0 => 2.13.3): Downloading (100%) - Updating doctrine/instantiator (1.3.0 => 1.3.1): Downloading (100%) - Updating doctrine/orm (v2.7.2 => v2.7.3): Downloading (100%) When accessing the site, I now have the following error: errno: 150 "Foreign key constraint is incorrectly formed I expected I should have first used concrete5's update script, but too late for that. So, then I changed composer.json require concrete5/core from ^8.5 to 8.5.2 hoping to return to the previous state. Concreete5 was downgraded as desired, but now I get the following error: Class 'Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain' not found On another concrete5 site which still works, I have the following two files, however, on the broken one I only have the second: vendor/doctrine/persistence/lib/Doctrine/Common/Persistence/Mapping/Driver/MappingDriverChain.php:13: class MappingDriverChain extends \Doctrine\Persistence\Mapping\Driver\MappingDriverChain vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/Driver/MappingDriverChain.php:17:class MappingDriverChain implements MappingDriver So, now I will attempt to downgrade doctrine from 2.7.3 to 2.7.2. The base composer.json file has no reference to Doctrine, but there are two other related composer files: vendor/concrete5/doctrine-xml/composer.json { "name": "concrete5/doctrine-xml", "description": "Define database structure via XML using Doctrine data types", "keywords": [ "doctrine", "xml", "structure", "database", "schema" ], "homepage": "https://github.com/concrete5/doctrine-xml", "license": "MIT", "autoload": { "psr-4": { "DoctrineXml\\": "src/" } }, "require": { "php": ">=5.3" }, "require-dev": { "doctrine/dbal": "2.5.*" } } vendor/concrete5/dependency-patches/composer.json { "type":"library", "license":"MIT", "name":"concrete5/dependency-patches", "description":"Patches required for concrete5 dependencies", "homepage":"https://github.com/concrete5/dependency-patches", "authors":[ { "name":"Michele Locati", "email":"michele@locati.it", "role":"author", "homepage":"https://mlocati.github.io" } ], "require":{ "mlocati/composer-patcher": "^1.0.0" }, "extra":{ "patches": { "doctrine/annotations:1.2.7": { "Fix access array offset on value of type null": "doctrine/annotations/access-array-offset-on-null.patch" }, "doctrine/orm:2.5.14": { "Fix UnitOfWork::createEntity()": "doctrine/orm/UnitOfWork-createEntity-continue.patch" }, "zendframework/zend-stdlib:2.7.7": { "Fix ArrayObject::unserialize()": "zendframework/zend-stdlib/ArrayObject-unserialize-continue.patch" }, "sunra/php-simple-html-dom-parser:1.5.2": { "Fix minus in regular expressions": "sunra/php-simple-html-dom-parser/minus-in-regular-expressions.patch" }, "phpunit/phpunit:4.8.36": { "Avoid each() in Getopt": "phpunit/phpunit/Getopt-each.patch" }, "tedivm/jshrink:1.1.0": { "Fix continue switch in Minifier": "tedivm/jshrink/fix-minifier-loop.patch", "Update to upstream version 1.3.2": "tedivm/jshrink/update-upstream-1.3.2.patch" }, "zendframework/zend-code:2.6.3": { "Fix continue switch in FileGenerator and MethodReflection": "zendframework/zend-code/switch-continue.patch" }, "zendframework/zend-http:2.6.0": { "Remove support for the X-Original-Url and X-Rewrite-Url headers": "zendframework/zend-http/no-x-original-url-x-rewrite.patch" }, "zendframework/zend-mail:2.7.3": { "Fix idn_to_ascii deprecation warning": "zendframework/zend-mail/fix-idn_to_ascii-deprecation-warning.patch" }, "zendframework/zend-validator:2.8.2": { "Fix idn_to_ascii/idn_to_utf8 deprecation warning": "zendframework/zend-validator/fix-idn_to_-deprecation-warning.patch" } } } } Neither seem to be applicable, but the doctrine version has to be specified somewhere. How does composer determine which version and how can I downgrade the dependency package? Thanks PS. As a hack solution, I replaced the entire vendor/doctrine directory from one from another site, and have things working. Still, want to know how to do this right.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.