@param Goal  $goal
@param Event $event
@param float $daily_budget

@return float
3364
private function calcEvent(Goal $goal, Event $event, $daily_budget) {
        $days_to_event = $this->calcDiffDays($goal->date_start, $event->date_start);
        $days_of_event = $this->calcDiffDays($event->date_start, $event->date_end);

        $daily_budget = new Number($daily_budget);
        $variation = new Percentage($event->variation);
        if ($this->current_date < $event->date_start) {

            $variated_budget = $daily_budget->preserve()
                ->bcadd($variation)
                ->bcsub($daily_budget)
                ->bcmul($days_of_event)
                ->bcdiv($days_to_event);

            $daily_budget->bcsub($variated_budget);

        } else if ($this->current_date >= $event->date_start && $this->current_date <= $event->date_end) {
            $daily_budget->bcadd($variation);
        }

        return $daily_budget->getValue();
    }
68371
def record_goal( goal, token )
      return true if winner_id

      return false unless goal = goal_hash[ goal ]
      return false unless subject = Subject.find_by_token( token )

      return true unless join = HypothesisSubject.find_by_experiment_id_and_subject_id( id, subject.id )
      return true if GoalSubject.find_by_goal_id_and_subject_id( goal.id, subject.id )

      GoalSubject.create( :goal_id => goal.id, :subject_id => subject.id, :experiment_id => id, :hypothesis_id => join.hypothesis_id)
      return true
    end
1311539
public function transferPoints($from, $to, $amount, $leaderTypeFrom = null, $leaderTypeTo = null)
    {   
        $availablePoints = $this->getTotal($from);
        $leaderboardTypeFrom = $this->getLeaderboardTypeService()->getLeaderboardTypeDefault();
        $leaderboardTypeTo = $this->getLeaderboardTypeService()->getLeaderboardTypeDefault();

        if (!empty($leaderTypeFrom)) {
            $leaderboardTypeFrom = $this->getLeaderboardTypeService()->getLeaderboardTypeMapper()->findOneBy(array('name' => $leaderTypeFrom));
        }
        if (!empty($leaderTypeTo)) {
            $leaderboardTypeTo = $this->getLeaderboardTypeService()->getLeaderboardTypeMapper()->findOneBy(array('name' => $leaderTypeTo));
        }

        if ($availablePoints >= $amount) {
            $this->add(-$amount, $from, $leaderboardTypeFrom);
            $this->add($amount, $to, $leaderboardTypeTo);

            return true;
        }

        return false;
    }
462725
public function daily($diff)
    {
        if (($diff->y == 0) && ($diff->m == 0) && (($diff->d == 0) || (($diff->d == 1) && ($diff->h == 0) && ($diff->i == 0)))) {
            return true;
        }
        return false;
    }
42948
protected function recordEcommerceItems($goal, $items)
    {
        $itemInCartBySku = array();
        foreach ($items as $item) {
            $itemInCartBySku[$item[0]] = $item;
        }

        $itemsInDb = $this->getModel()->getAllItemsCurrentlyInTheCart($goal, self::ITEM_IDORDER_ABANDONED_CART);

        // Look at which items need to be deleted, which need to be added or updated, based on the SKU
        $skuFoundInDb = $itemsToUpdate = array();

        foreach ($itemsInDb as $itemInDb) {
            $skuFoundInDb[] = $itemInDb['idaction_sku'];

            // Ensure price comparisons will have the same assumption
            $itemInDb['price'] = $this->getRevenue($itemInDb['price']);
            $itemInDbOriginal = $itemInDb;
            $itemInDb = array_values($itemInDb);

            // Cast all as string, because what comes out of the fetchAll() are strings
            $itemInDb = $this->getItemRowCast($itemInDb);

            //Item in the cart in the DB, but not anymore in the cart
            if (!isset($itemInCartBySku[$itemInDb[0]])) {
                $itemToUpdate = array_merge($itemInDb,
                    array('deleted'                => 1,
                          'idorder_original_value' => $itemInDbOriginal['idorder_original_value']
                    )
                );

                $itemsToUpdate[] = $itemToUpdate;
                Common::printDebug("Item found in the previous Cart, but no in the current cart/order");
                Common::printDebug($itemToUpdate);
                continue;
            }

            $newItem = $itemInCartBySku[$itemInDb[0]];
            $newItem = $this->getItemRowCast($newItem);

            if (count($itemInDb) != count($newItem)) {
                Common::printDebug("ERROR: Different format in items from cart and DB");
                throw new Exception(" Item in DB and Item in cart have a different format, this is not expected... " . var_export($itemInDb, true) . var_export($newItem, true));
            }
            Common::printDebug("Item has changed since the last cart. Previous item stored in cart in database:");
            Common::printDebug($itemInDb);
            Common::printDebug("New item to UPDATE the previous row:");
            $newItem['idorder_original_value'] = $itemInDbOriginal['idorder_original_value'];
            Common::printDebug($newItem);
            $itemsToUpdate[] = $newItem;
        }

        // Items to UPDATE
        $this->updateEcommerceItems($goal, $itemsToUpdate);

        // Items to INSERT
        $itemsToInsert = array();
        foreach ($items as $item) {
            if (!in_array($item[0], $skuFoundInDb)) {
                $itemsToInsert[] = $item;
            }
        }

        $this->insertEcommerceItems($goal, $itemsToInsert);
    }
1202025
def prop_budget(self, budget):
        

        if self.minicard:
            pysolvers.minicard_pbudget(self.minicard, budget)
1358201
def prop_budget(self, budget):
        

        if self.minisat:
            pysolvers.minisat22_pbudget(self.minisat, budget)
275305
public function getAllTrafficSources_Goals($parameters = [], $parseResult = true)
    {
        $this->setParams([
            'metrics'    => 'ga:sessions,ga:goal1Starts,ga:goal1Completions,ga:goal1Value,ga:goalStartsAll,ga:goalCompletionsAll,ga:goalValueAll',
            'dimensions' => 'ga:source,ga:medium',
            'sort'       => '-ga:goalCompletionsAll',
        ]);

        return $this->execute($parameters, $parseResult);
    }
306921
public function monthly($year, $month, $page = 1, $limit = 25)
    {
        return $this->client->call("expenses/in_month/{$year}/{$month}", [
            'page' => $page,
            'per_page' => $limit
        ], 'GET');
    }
146674
@UiHandler("m_everyDay")
    void onEveryDayChange(ValueChangeEvent<String> event) {

        if (handleChange()) {
            m_controller.setInterval(m_everyDay.getFormValueAsString());
        }

    }
736896
public function getAllEventsHook($allEvents, $calendars, $start, $end, $module)
	{
		if (!($permissions = static::checkLogin()) || !in_array('beModules', $permissions)) {
			return $allEvents;
		}

		foreach ($allEvents as $key => $days) {
			foreach ($days as $day => $events) {
				foreach ($events as $index => $event) {
					$allEvents[$key][$day][$index]['class'] =
						(empty($event['class']) ? '' : $event['class'])
						. ' rsfh-event-' . $event['id'];
				}
			}
		}

		return $allEvents;
	}
714415
public function onGoalConversion(Request $request, Visitor $visitor, $action, GoalManager $goalManager)
    {
        $defaultRevenue = $goalManager->getGoalColumn('revenue');
        $revenue        = $request->getGoalRevenue($defaultRevenue);

        return $this->roundRevenueIfNeeded($revenue);
    }
971288
public function filter($table)
    {
        // Add standard processed metrics
        parent::filter($table);

        $goals = $this->getGoalsInTable($table);
        if (!empty($this->goalsToProcess)) {
            $goals = array_unique(array_merge($goals, $this->goalsToProcess));
            sort($goals);
        }

        $idSite = DataTableFactory::getSiteIdFromMetadata($table);

        $extraProcessedMetrics = $table->getMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME);

        $extraProcessedMetrics[] = new RevenuePerVisit();
        if ($this->processOnlyIdGoal != self::GOALS_MINIMAL_REPORT) {
            foreach ($goals as $idGoal) {
                if (($this->processOnlyIdGoal > self::GOALS_FULL_TABLE
                        || $this->isEcommerce)
                    && $this->processOnlyIdGoal != $idGoal
                ) {
                    continue;
                }

                $extraProcessedMetrics[] = new ConversionRate($idSite, $idGoal); // PerGoal\ConversionRate

                // When the table is displayed by clicking on the flag icon, we only display the columns
                // Visits, Conversions, Per goal conversion rate, Revenue
                if ($this->processOnlyIdGoal == self::GOALS_OVERVIEW) {
                    continue;
                }

                $extraProcessedMetrics[] = new Conversions($idSite, $idGoal); // PerGoal\Conversions or GoalSpecific\
                $extraProcessedMetrics[] = new GoalSpecificRevenuePerVisit($idSite, $idGoal); // PerGoal\Revenue
                $extraProcessedMetrics[] = new Revenue($idSite, $idGoal); // PerGoal\Revenue

                if ($this->isEcommerce) {
                    $extraProcessedMetrics[] = new AverageOrderRevenue($idSite, $idGoal);
                    $extraProcessedMetrics[] = new ItemsCount($idSite, $idGoal);
                }
            }
        }

        $table->setMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME, $extraProcessedMetrics);
    }
1180939
function(elem, target) {
				this.selectDateOrig(elem, target);
				var inst = $.calendarsPicker._getInst(elem);
				if (!inst.inline && $.fn.validate) {
					var validation = $(elem).parents('form').validate();
					if (validation) {
						validation.element('#' + elem.id);
					}
				}
			}
154046
public function getProvisionRelatedLdapEntry($account, $prov_events = NULL) {
    if (!$prov_events) {
      $prov_events = ldap_user_all_events();
    }
    $sid = $this->ldapEntryProvisionServer; //
    //debug("ldapEntryProvisionServer:$sid");
    if (!$sid) {
      return FALSE;
    }
    // $user_entity->ldap_user_prov_entries,
    $ldap_server = ldap_servers_get_servers($sid, NULL, TRUE);
    $params = array(
      'direction' => LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY,
      'prov_events' => $prov_events,
      'module' => 'ldap_user',
      'function' => 'getProvisionRelatedLdapEntry',
      'include_count' => FALSE,
      );
    list($proposed_ldap_entry, $error) = $this->drupalUserToLdapEntry($account, $ldap_server, $params);
    if (!(is_array($proposed_ldap_entry) && isset($proposed_ldap_entry['dn']) && $proposed_ldap_entry['dn'])) {
      return FALSE;
    }
    $ldap_entry = $ldap_server->dnExists($proposed_ldap_entry['dn'], 'ldap_entry', array());
    return $ldap_entry;

  }
438906
public function defineGoal() {
    /**
     * To test generate Members, create MemberCampaign record and run code in /devel/php
     *
     * $entity = \Drupal\openy_campaign\Entity\MemberCampaign::load(1);
     * $entity->defineGoal();
     *
     * Needs actual data in order to proceed.
     */

    /** @var \Drupal\node\Entity\Node $campaign Current campaign */
    $campaign = $this->getCampaign();

    // Get all enabled activities list.
    $activitiesOptions = openy_campaign_get_enabled_activities($campaign);

    // For disabled Visits Goal activity.
    if (!in_array('field_prgf_activity_visits', $activitiesOptions)) {
      $this->setGoal(0);
      return TRUE;
    }

    $current = new \DateTime();
    $from = new \DateTime($campaign->field_goal_check_ins_start_date->value);
    $to = new \DateTime($campaign->field_goal_check_ins_end_date->value);

    // We should not call CRM for the future date.
    if ($current < $to) {
      $to = $current;
    }

    $member = $this->getMember();

    /** @var $client \Drupal\openy_campaign\CRMClientInterface */
    $client = \Drupal::getContainer()->get('openy_campaign.client_factory')->getClient();
    // Get total visits from CRM.
    $results = $client->getVisitCountByDate($member->getPersonifyId(), $from, $to);

    $visitsNumber = $results->TotalVisits;

    // Visits goal will be between these 2 values.
    $maxVisitsGoal = $campaign->field_limit_visits_goal->value;
    $minVisitsGoal = $campaign->field_min_visits_goal->value;

    $weeksSpan = ceil($from->diff($to)->days / 7);

    $calculatedGoal = ceil(2 * $visitsNumber / $weeksSpan) + 1;
    $visitsGoal = max($minVisitsGoal, $calculatedGoal);

    $goal = min($visitsGoal, $maxVisitsGoal);

    $this->setGoal($goal);

    return TRUE;
  }
60677
protected function updateEcommerceItems($goal, $itemsToUpdate)
    {
        if (empty($itemsToUpdate)) {
            return;
        }

        Common::printDebug("Goal data used to update ecommerce items:");
        Common::printDebug($goal);

        foreach ($itemsToUpdate as $item) {
            $newRow = $this->getItemRowEnriched($goal, $item);
            Common::printDebug($newRow);

            $this->getModel()->updateEcommerceItem($item['idorder_original_value'], $newRow);
        }
    }