Example #1
0
 /**
  * Train On File.
  * 
  * @return bool
  */
 public function trainOnFile()
 {
     $maxEpochs = 500000;
     $epochsBetweenReports = 1000;
     $desiredError = 0.001;
     $result = $this->neuralNetwork->trainOnFile($maxEpochs, $epochsBetweenReports, $desiredError);
     if ($result === false) {
         throw new RuntimeException(sprintf("Failed to train neural network on file: %s", $this->neuralNetwork->getConfigurationFile()), 1);
     }
     $result = $this->neuralNetwork->save();
     if ($result === false) {
         throw new RuntimeException(sprintf("Failed to save neural network to file: %s", $this->neuralNetwork->getConfigurationFile()), 1);
     }
     return $result;
 }
Example #2
0
 /**
  * Move file from the temporary destination to the original destination
  *
  * @param \stdClass $file
  * @throws File\Exception
  */
 public static final function moveFile($file)
 {
     try {
         if ($file->is_temp) {
             rename($file->temp_destination . '/' . $file->temp_name, $file->original_destination . '/' . $file->temp_name);
             if (!file_exists($file->original_destination . '/' . $file->temp_name)) {
                 throw new CannotSaveFileInHardDriveException();
             }
             $file->is_temp = false;
             $file->expire = null;
             $file->save();
         }
     } catch (\Exception $exception) {
         throw new FileException($exception->getMessage());
     }
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $shipment = new \stdClass();
     $shipment->order_id = $form_state->getValue('order_id');
     if ($form_state->hasValue('sid')) {
         $shipment->sid = $form_state->getValue('sid');
     }
     $shipment->origin = (object) $form_state->getValue('pickup_address');
     $shipment->destination = new \stdClass();
     foreach ($form_state->getValues() as $key => $value) {
         if (substr($key, 0, 9) == 'delivery_') {
             $field = substr($key, 9);
             $shipment->destination->{$field} = $value;
         }
     }
     $shipment->packages = array();
     foreach ($form_state->getValue('packages') as $id => $pkg_form) {
         $package = Package::load($id);
         $package->pkg_type = $pkg_form['pkg_type'];
         $package->value = $pkg_form['declared_value'];
         $package->length = $pkg_form['dimensions']['length'];
         $package->width = $pkg_form['dimensions']['width'];
         $package->height = $pkg_form['dimensions']['height'];
         $package->length_units = $pkg_form['dimensions']['units'];
         $package->tracking_number = $pkg_form['tracking_number'];
         $package->qty = 1;
         $shipment->packages[$id] = $package;
     }
     $shipment->shipping_method = $form_state->getValue('shipping_method');
     $shipment->accessorials = $form_state->getValue('accessorials');
     $shipment->carrier = $form_state->getValue('carrier');
     $shipment->transaction_id = $form_state->getValue('transaction_id');
     $shipment->tracking_number = $form_state->getValue('tracking_number');
     $shipment->ship_date = $form_state->getValue('ship_date')->getTimestamp();
     $shipment->expected_delivery = $form_state->getValue('expected_delivery')->getTimestamp();
     $shipment->cost = $form_state->getValue('cost');
     $shipment->save();
     $form_state->setRedirect('uc_fulfillment.shipments', ['uc_order' => $form_state->getValue('order_id')]);
 }