<commit_before><?php
use google\appengine\datastore\v4\BeginTransactionRequest;
use google\appengine\datastore\v4\BeginTransactionResponse;
use google\appengine\datastore\v4\CommitRequest;
use google\appengine\datastore\v4\CommitRequest\Mode;
use google\appengine\datastore\v4\CommitResponse;
use google\appengine\datastore\v4\Key;
use google\appengine\datastore\v4\LookupRequest;
use google\appengine\datastore\v4\LookupResponse;
use google\appengine\datastore\v4\PropertyFilter;
use google\appengine\datastore\v4\QueryResultBatch;
use google\appengine\datastore\v4\RunQueryRequest;
use google\appengine\datastore\v4\RunQueryResponse;
use google\appengine\datastore\v4\Value;
use google\appengine\runtime\ApiProxy;
use google\appengine\runtime\ApplicationError;
use google\net\ProtocolMessage;
use google\appengine\datastore\v4\PropertyFilter\Operator;
use google\appengine\datastore\v4\PropertyOrder\Direction;
use google\appengine\datastore\v4\EntityResult;

// CloudSQL Class v10
if (!defined ("_DATASTORE_CLASS_") ) {
    define("_DATASTORE_CLASS_", TRUE);

    class DataStoreTypes {
        const key = 'key';
        const keyname = 'keyname';
        const boolean = 'boolean';
        const integer =  'integer';
        const date =  'date';
        const datetime =  'datetime';
        const float =  'float';
        const list_elements =  'list';
        const geo =  'bool';
    }

    class DataStore
    {
        var $error = false;
        var $errorMsg = '';
        var $store = null;
        var $entity_schema = null;
        var $entity_name = null;
        var $entity_gw = null;
        var $schema = [];
        var $lastQuery = '';
        var $core = null;
        var $types = null;

        function __construct(Core &$core, $params)
        {
            $this->core = $core;
            $entity = $params[0];
            $namespace = (isset($params[1]))?$params[1]:null;
            $schema = (isset($params[2]))?$params[2]:null;

            $this->core->__p->add('DataStore new instance ', '', 'note');
            $this->entity_name = $entity;
            $this->entity_schema = $this->getEntitySchema($entity, $schema);
            if(!$this->error) {
                if (null !== $namespace && strlen($namespace)) {
                    $this->entity_gw = new ProtoBuf(null, $namespace);
                }
                $this->store = new Store($this->entity_schema, $this->entity_gw);
            }
            $this->core->__p->add('DataStore new instance ', '', 'endnote');


        }

        function createEntities($data)
        {
            if ($this->error) return false;
            $ret = [];
            if (!is_array($data)) $this->setError('No data received');
            else {
                $this->core->__p->add('createEntities: ', $this->entity_name, 'note');

                // converting $data into n,n dimmensions
                if (!is_array($data[0])) $data = [$data];

                // loop the array into $row
                foreach ($data as $i => $row) {
                    $record = [];
                    $schema_key = null;
                    $schema_keyname = null;

                    // Loading info from Data. $i can be numbers 0..n or indexes.
                    foreach ($row as $i => $value) {

                        // Only use those variables that appears in the schema.
                        if(!isset($this->schema['props'][$i])) {
                            continue;
                        }
                        // if the field is key or keyname feed $schema_key or $schema_keyname
                        if ($this->schema['props'][$i][1] == 'key') {
                            $schema_key =  preg_replace('/[^0-9]/','' ,$value );
                            if(!strlen($schema_key)) $this->setError('wrong Key value');

                        } elseif ($this->schema['props'][$i][1] == 'keyname') {
                            $schema_keyname = $value;

                        // else explore the data.
                        } else {
                            if (is_string($value)) {
                                // date & datetime values
                                if ($this->schema['props'][$i][1] == 'date' || $this->schema['props'][$i][1] == 'datetime') {
                                    if ($this->schema['props'][$i][1] == 'date') $value = substr($value, 0, 10);
                                    try {
                                        $value_time = new DateTime($value);
                                        $value = $value_time;
                                    } catch (Exception $e) {
                                        $ret[] = ['error' => 'field {' . $this->schema['props'][$i][0] . '} has a wrong date format: ' . $value];
                                        $record = [];
                                        break;
                                    }
                                // geo values
                                } elseif($this->schema['props'][$i][1] == 'geo') {<commit_msg>Fix date in DataStore and Pymefy<commit_after><?php
use google\appengine\datastore\v4\BeginTransactionRequest;
use google\appengine\datastore\v4\BeginTransactionResponse;
use google\appengine\datastore\v4\CommitRequest;
use google\appengine\datastore\v4\CommitRequest\Mode;
use google\appengine\datastore\v4\CommitResponse;
use google\appengine\datastore\v4\Key;
use google\appengine\datastore\v4\LookupRequest;
use google\appengine\datastore\v4\LookupResponse;
use google\appengine\datastore\v4\PropertyFilter;
use google\appengine\datastore\v4\QueryResultBatch;
use google\appengine\datastore\v4\RunQueryRequest;
use google\appengine\datastore\v4\RunQueryResponse;
use google\appengine\datastore\v4\Value;
use google\appengine\runtime\ApiProxy;
use google\appengine\runtime\ApplicationError;
use google\net\ProtocolMessage;
use google\appengine\datastore\v4\PropertyFilter\Operator;
use google\appengine\datastore\v4\PropertyOrder\Direction;
use google\appengine\datastore\v4\EntityResult;

// CloudSQL Class v10
if (!defined ("_DATASTORE_CLASS_") ) {
    define("_DATASTORE_CLASS_", TRUE);

    class DataStoreTypes {
        const key = 'key';
        const keyname = 'keyname';
        const boolean = 'boolean';
        const integer =  'integer';
        const date =  'date';
        const datetime =  'datetime';
        const float =  'float';
        const list_elements =  'list';
        const geo =  'bool';
    }

    class DataStore
    {
        var $error = false;
        var $errorMsg = '';
        var $store = null;
        var $entity_schema = null;
        var $entity_name = null;
        var $entity_gw = null;
        var $schema = [];
        var $lastQuery = '';
        var $core = null;
        var $types = null;

        function __construct(Core &$core, $params)
        {
            $this->core = $core;
            $entity = $params[0];
            $namespace = (isset($params[1]))?$params[1]:null;
            $schema = (isset($params[2]))?$params[2]:null;

            $this->core->__p->add('DataStore new instance ', '', 'note');
            $this->entity_name = $entity;
            $this->entity_schema = $this->getEntitySchema($entity, $schema);
            if(!$this->error) {
                if (null !== $namespace && strlen($namespace)) {
                    $this->entity_gw = new ProtoBuf(null, $namespace);
                }
                $this->store = new Store($this->entity_schema, $this->entity_gw);
            }
            $this->core->__p->add('DataStore new instance ', '', 'endnote');


        }

        function createEntities($data)
        {
            if ($this->error) return false;
            $ret = [];
            if (!is_array($data)) $this->setError('No data received');
            else {
                $this->core->__p->add('createEntities: ', $this->entity_name, 'note');

                // converting $data into n,n dimmensions
                if (!is_array($data[0])) $data = [$data];

                // loop the array into $row
                foreach ($data as $i => $row) {
                    $record = [];
                    $schema_key = null;
                    $schema_keyname = null;

                    // Loading info from Data. $i can be numbers 0..n or indexes.
                    foreach ($row as $i => $value) {

                        // Only use those variables that appears in the schema.
                        if(!isset($this->schema['props'][$i])) {
                            continue;
                        }
                        // if the field is key or keyname feed $schema_key or $schema_keyname
                        if ($this->schema['props'][$i][1] == 'key') {
                            $schema_key =  preg_replace('/[^0-9]/','' ,$value );
                            if(!strlen($schema_key)) $this->setError('wrong Key value');

                        } elseif ($this->schema['props'][$i][1] == 'keyname') {
                            $schema_keyname = $value;

                        // else explore the data.
                        } else {
                            if (is_string($value)) {
                                // date & datetime values
                                if ($this->schema['props'][$i][1] == 'date' || $this->schema['props'][$i][1] == 'datetime') {
                                    if(strlen($value)) {
                                        if ($this->schema['props'][$i][1] == 'date') $value = substr($value, 0, 10);
                                        try {
                                            $value_time = new DateTime($value);
                                            $value = $value_time;
                                        } catch (Exception $e) {
                                            $ret[] = ['error' => 'field {' . $this->schema['props'][$i][0] . '} has a wrong date format: ' . $value];
                                            $record = [];
                                            break;
                                        }
                                    }
                                // geo values
                                } elseif($this->schema['props'][$i][1] == 'geo') {
{'fraction_non_alphanumeric': 0.13686770428015566, 'fraction_numerical': 0.0071984435797665365, 'mean_word_length': 1.5229447852760736, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 35, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5181776', 'n_tokens_mistral': 2804, 'n_tokens_neox': 2728, 'n_words': 572}