Recommend this page to a friend! |
Download |
Info | Example | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not yet rated by the users | Total: 77 | All time: 10,159 This week: 455 |
Version | License | PHP version | Categories | |||
chaosmachineone 1.0.0 | GNU Lesser Genera... | 5 | Algorithms, PHP 5, Statistics, Math |
<?php |
A controlled random generator data for PHP. It doesn't chart visually, the objective is to generate values to store into the database (mysql)
Sometimes we want to generate fake values for the database that are controlled and consistent. So, this library tries to create an ordered chaos.
Let's say the next exercise. We want to generate random values for a new system (sales)
If we generate random values, the chart would look like
> ->gen('when _index<200 then idtable.value=random(-10,10,0.2)')
Why is it so random? it is because they are random values (doh). So, they are right but they don't looks real because there is not a trend or a natural flow of information, it is just static noise.
Then, let's generate the same value with a sine (for example, let's say that there is a cycle of sales)
> ->gen('when _index<200 then idtable.add=sin(0,0,10,30)')
The chart has a trend but it is too predictable. So, let's add all factors.
> ->gen('when _index<200 then idtable.value=random(-10,10,0.2) and idtable.add=sin(0,0,10,30)')
While this chart is far from real, but it is not TOO RANDOM and it has a trend.
> field($name,$type,$special='database',$initValue=0,$min=PHP_INT_MIN,$max=PHP_INT_MAX)
fields are our values. They could be numeric, date and string.
Examples: > "set field.value=20" // it sets the value of the field to 20 > "set field.speed=3" // it sets the speed of the field by 3. The field increases the value every cycle by 3 > "set field.accel=1" // it sets the acceleration of the field by 1. The field increases the speed every cycle by 1 > "set field.value=30 and field.speed=1" // the value is always 30, no matter the speed
->gen('when _index<40 then idtable.accel=1') // the acceleration is 1 until index=40
->gen('when _index<60 then idtable.accel=-1') // the acceleration is -1 until index=60
->gen('when _index<100 then idtable.accel=-1') // the acceleration is -1 until index=100
It generates a value using the Minilang syntaxis.
The syntaxis is as follow:
when logic and/or logic2 and/or logic3 then setvalue1 , setvalue2 , setvalue3
| Variable | Explanation | Example | |----------------------------------------------------|-----------------------------------------------------|--------------------------------------| | $var | it is php global variable. | $var="hi" | | field | it is an minilang variable. | field | | field.value it is the value of a column (if any) | field.value="hi" | | | _index | indicates the current index (current number of row) | _index<200 | | 20 , 20.50 | its a fixed value | 20,50.3 | | "text",'text' | it is fixed string value | "text",'text' | | fn() | its a function | myfunction(value), some.myfunction() |
| Reserved word | Explanation | |---------------|------------------------------------------------------------------------------| | null | null value | | false | false value | | true | true value | | on | 1 | | off | 0 | | undef | -1 (for undefined) | | flip | (special value). It inverts a value ON<->OFF<br>Used as value.flip | | now | returns the current timestamp (integer) | | timer | returns the current timestamp (integer) | | interval | returns the interval (in seconds) between the last change and now | | fullinterval | returns the interval (in seconds) between the start of the process and now | | _index | returns the current index (the current counter of row) | | always | reserved word. It is used as "when always" |
Examples:
myvar = is a variable
> when always set myvar.value=null > when _index<20 set myvar.value=false
Limits. * Parenthesis are now allowed (unless it is defines a function). > a1=(20+30) is not allowed however a1=20 , a1+30 is allowed * The syntax is divided in two parts, one of the logic (when) and other is the set (then) * Conditions are evaluated in order. If one condition is meet, then it stop other evaluations. > when a1=1 then b1=1 > when a1<10 then b1=10 // if a1=1 then this expression is not evaluated.
It sets the condition(s) separated by and or or
> It is not allowed to use more than operator for logic. a1=20+30 is not allowed.
Functions that generates a range of values
It generates a ramp values (lineal values)
->gen('when _index<200 then idtable.value=ramp(0,100,10,1000)')
->gen('when _index<200 then idtable.value=ramp(0,100,1000,10)')
It generates log values
> ->gen('when _index<200 then idtable.value=log(0,0,100)')
It generates exponential values. The scale is for division of Y
> ->gen('when _index<200 then idtable.value=exp(0,0,10)')
It generates a sinuzoid values. The angle is calculated with the current index x the speed (in degree)
> ->gen('when _index<200 then idtable.value=sin(0,0,1,1)')
> ->gen('when _index<200 then idtable.value=sin(0,0,10,1)')
It generates arc-tangent values
->gen('when _index<200 then idtable.value=atan(50,0,20,10)')
It generates a parabola. It is possible to invert the parabola by changing the scaleA by negative
> ->gen('when _index<200 then idtable.value=parabola(50,0,1,1,1)')
> ->gen('when _index<200 then idtable.value=parabola(50,0,-1,1,1)')
> ->gen('when _index<200 then idtable.value=parabola(50,2500,-1,1,1)')
It generates a bell values, sigma is the "wide" of the bell.
> ->gen('when _index<=360 then idtable.value=bell(50,0,30,100)')
> ->gen('when _index<=360 then idtable.value=bell(50,0,30,100)')
Functions that generates a single value
It generates a random value by using different proportions or probabilities.
> randomprop(1,2,3,30,50,20)
> ->gen('when _index<200 then idtable.value=randomprop(1,2,3,30,50,20)') > ->gen('when always then idtable.value=randomprop(idtable,null,1,1)) // there is a 50% chance the value is null
It generates a random value from $from to $to.
random(1,10) // 1,2,3,4,5,6,7,8,9,10
random(1,10,2) // 1,3,5,7,9
> ->gen('when _index<200 then idtable.value=random(-10,10,0.2)')
Optionally, you could add a probability for each segment.
> random(0,100,1,10,20,70)
> idtable.value=random(0,200,1,80,10,10)
> idtable.value=random(0,200,1,10,80,10)
> idtable.value=random(0,200,1,10,10,80)
It sets the speed of the field. If the field has speed then it's value it's increased for each iteraction.
It sets the acceleration of a field. If the field has acceleration then it's speed it's increased for each iteraction.
It sets the value of a field
It returns the value of a field
It transform the value of a field to absolute (always positive)
It returns the current part of the date (day,month,year,hour,minute and weekday).
> It is used for field of the type datetime. > It is not for set, no matter the value. > Weekday = 1= monday, 7=sunday
It sets or returns the value of a field, it also marks the speed and acceleration to zero.
It adds a value to a field. If the field is of the type datetime, then you could add an "hour","minute" and "day"
field.add=20 // add 20 to the field
field.add="5h" // adds 5 hours to the field. 5m = 5 minutes, 5d = 5 days
It concatenates a value to a field.
field.concat=20
field.concat="abc"
It skips a value to the next value. It is used for date.
| value | |--------------| | hour | | day | | month | | monday | | tuesday | | wednesday | | thursday | | friday | | saturday | | sunday |
field.skip='day' // it skips to the next day (it start at 00:00)
field.skip='month' // it skips to the next month (it start at the first day of the month 00:00)
field.skip='monday' // (or the name of the day), it skips to the next monday (00:00 hours)
field.skip='hour' // it skips to the next hour (minute 00)
It sets an array. If the array is associative, then the value is the probability of selection.
->setArray('arrayname',['a','b','c']) // it sets an array with 3 values with the same chances.
->setArray('arrayname',['a'=>80,'b'=>10,'c'=>10]) // it sets an array with 3 values with the changes of a(80%),b(10%) and c(10%)
It sets a format (template) to merge different arrays. The arrays are marked as {{name-of-the-array}}. If the array is not defined then it returns the value of a field.
If the array is associative then it returns a value according it's probability.
->setFormat('maleNameFormats',['{{namearr}} {{lastnamearr}}','Dr.{{namearr}} {{lastnamearr}}'])
->setFormat('maleNameFormats',['{{namearr}} {{lastnamearr}}'=>80,'Dr.{{namearr}} {{lastnamearr}}'=>20]) //probability of 80% and 20%
it returns a random row inside of the array declared with setArray(). If the array is associative then it returns a value according it's probability.
If the array is a list of objects, then it returns the value of the field.
->gen('when always set name.value=randomarray("arrayname")')
It generates a random text using a mixes of format and different arrays.
->gen('when always set fullname.value=randomformat("nameFormat")')
It generates a random text by using the array with name $arrayName. The text could starts with a default text.
If $paragraph is not 0, then it could generates paragraph (line carriage)
->gen('when always then text.value=randomtext("Lorem ipsum dolor","loremIpsumArray",1,4,30)')
It generates a text based on a mask
> randommask("##-00 uu ll \0 - oo (a)","lastName") // where lastName is an array
It reads a folder and returns an array of files. The reading is not recursive and it could be filtered by extension.
> $filesWithoutExtension=$chaos->arrayFromFolder($localfolder,'jpg',false);
It copies a file from a location to another.
->gen('when always set ImageDestination.copyfilefrom=ImageSource.getvalue')
Files (76) |
File | Role | Description | ||
---|---|---|---|---|
docs (27 files) | ||||
exercise (8 files, 2 directories) | ||||
lib (2 files, 1 directory) | ||||
tests (2 files) | ||||
.travis.yml | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
phpunit.xml | Data | Auxiliary data | ||
README.md | Doc. | Documentation |
Files (76) | / | docs |
File | Role | Description |
---|---|---|
accel.jpg | Icon | Icon image |
atan.jpg | Icon | Icon image |
bell1.jpg | Icon | Icon image |
bell30.jpg | Icon | Icon image |
count.jpg | Icon | Icon image |
dummychart.jpg | Icon | Icon image |
empty.jpg | Icon | Icon image |
examplecount.jpg | Icon | Icon image |
examplesum.jpg | Icon | Icon image |
exampleweekday.jpg | Icon | Icon image |
exp.jpg | Icon | Icon image |
log.jpg | Icon | Icon image |
parabola1.jpg | Icon | Icon image |
parabola2.jpg | Icon | Icon image |
parabola3.jpg | Icon | Icon image |
ramp.jpg | Icon | Icon image |
ramp2.jpg | Icon | Icon image |
random.jpg | Icon | Icon image |
random101080.jpg | Icon | Icon image |
random108010.jpg | Icon | Icon image |
random801010.jpg | Icon | Icon image |
randomprop.jpg | Icon | Icon image |
randomsin.jpg | Icon | Icon image |
random_.jpg | Icon | Icon image |
sin1.jpg | Icon | Icon image |
sin10.jpg | Icon | Icon image |
sin1030.jpg | Icon | Icon image |
Files (76) | / | exercise |
File | Role | Description | ||
---|---|---|---|---|
databasefile (1 file) | ||||
machines (29 files) | ||||
example1.php | Class | Class source | ||
example2.php | Example | Example script | ||
examplearray.php | Example | Example script | ||
exampledb.php | Example | Example script | ||
exampledbselfgen.php | Example | Example script | ||
exampledbselfgen2.php | Example | Example script | ||
exampleproducts.php | Example | Example script | ||
exampletime.php | Example | Example script |
Files (76) | / | exercise | / | machines |
File | Role | Description |
---|---|---|
1122290.jpg | Icon | Icon image |
1509144.jpg | Icon | Icon image |
1612646.jpg | Icon | Icon image |
1615971.jpg | Icon | Icon image |
1622390.jpg | Icon | Icon image |
1839314.jpg | Icon | Icon image |
1839322.jpg | Icon | Icon image |
3174824.jpg | Icon | Icon image |
3398137.jpg | Icon | Icon image |
3401715.jpg | Icon | Icon image |
3401723.jpg | Icon | Icon image |
3401731.jpg | Icon | Icon image |
340174X.jpg | Icon | Icon image |
3401758.jpg | Icon | Icon image |
37478.jpg | Icon | Icon image |
3773639.jpg | Icon | Icon image |
3773647.jpg | Icon | Icon image |
3773663.jpg | Icon | Icon image |
3773671.jpg | Icon | Icon image |
377368X.jpg | Icon | Icon image |
3773698.jpg | Icon | Icon image |
3773701.jpg | Icon | Icon image |
377371X.jpg | Icon | Icon image |
3773728.jpg | Icon | Icon image |
3773736.jpg | Icon | Icon image |
3773744.jpg | Icon | Icon image |
3792560.jpg | Icon | Icon image |
584347.jpg | Icon | Icon image |
831263.jpg | Icon | Icon image |
Files (76) | / | lib |
File | Role | Description | ||
---|---|---|---|---|
en_US (2 files) | ||||
ChaosField.php | Class | Class source | ||
ChaosMachineOne.php | Class | Class source |
Files (76) | / | lib | / | en_US |
File | Role | Description |
---|---|---|
Person.php | Class | Class source |
Products.php | Class | Class source |
Files (76) | / | tests |
File | Role | Description |
---|---|---|
AbstractStateMachineOneTestCase.php | Class | Class source |
CompilationTest.php | Class | Class source |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.