public function search(Request $request) { $results = array(); $term = $request->get('term'); $goals = Goal::where('body', 'like', '%' . $term . '%')->orderBy('body', 'asc')->get(); $objectives = Objective::where('body', 'like', '%' . $term . '%')->orderBy('body', 'asc')->get(); $actions = Action::where('body', 'like', '%' . $term . '%')->orderBy('body', 'asc')->get(); $tasks = Task::where('body', 'like', '%' . $term . '%')->orderBy('body', 'asc')->get(); $teams = Team::where('name', 'like', '%' . $term . '%')->orderBy('name', 'asc')->get(); $departments = Department::where('name', 'like', '%' . $term . '%')->orderBy('name', 'asc')->get(); $users = User::where('name', 'like', '%' . $term . '%')->orderBy('name', 'asc')->get()->all(); foreach (User::where('email', 'like', '%' . $term . '%')->orderBy('name', 'asc')->get() as $matching_user_email) { if (in_array($matching_user_email, $users)) { continue; } $users[] = $matching_user_email; } $notes = Note::where('content', 'like', '%' . $term . '%')->orderBy('content', 'asc')->get(); $types = [$goals, $objectives, $actions, $tasks, $teams, $departments, $users, $notes]; foreach ($types as $type) { foreach ($type as $result) { $results[] = $result; } } return view('search.show')->with('results', $results)->with('term', $term); }
/** * Run the migrations. * * @return void */ public function up() { $actions = Action::where('action', 'signed up')->get(); foreach ($actions as $action) { Signup::firstOrCreate(['campaign_id' => $action->campaign_id, 'contact_id' => $action->contact_id]); } }
public function sendNotificationEmail(Group $group, User $user) { if ($user->verified == 1) { // Establish timestamp for notifications from membership data (when was an email sent for the last time?) $membership = \App\Membership::where('user_id', '=', $user->id)->where('group_id', "=", $group->id)->firstOrFail(); $last_notification = $membership->notified_at; // find unread discussions since timestamp $discussions = QueryHelper::getUnreadDiscussionsSince($user->id, $group->id, $membership->notified_at); // find new files since timestamp $files = \App\File::where('updated_at', '>', $membership->notified_at)->where('group_id', "=", $group->id)->get(); // find new members since timestamp $users = QueryHelper::getNewMembersSince($user->id, $group->id, $membership->notified_at); // find future actions until next 2 weeks, this is curently hardcoded... TODO use the mail sending interval to determine stop date $actions = \App\Action::where('start', '>', Carbon::now())->where('stop', '<', Carbon::now()->addWeek()->addWeek())->where('group_id', "=", $group->id)->orderBy('start')->get(); // we only trigger mail sending if a new action has been **created** since last notfication email. // BUT we will send actions for the next two weeks in all cases, IF a mail must be sent $actions_count = \App\Action::where('created_at', '>', $membership->notified_at)->where('group_id', "=", $group->id)->count(); // in all cases update timestamp $membership->notified_at = Carbon::now(); $membership->save(); // if we have anything, build the message and send // removed that : or count($users) > 0 // because we don't want to be notified just because there is a new member if (count($discussions) > 0 or count($files) > 0 or $actions_count > 0) { Mail::send('emails.notification', ['user' => $user, 'group' => $group, 'membership' => $membership, 'discussions' => $discussions, 'files' => $files, 'users' => $users, 'actions' => $actions, 'last_notification' => $last_notification], function ($message) use($user, $group) { $message->from(env('MAIL_NOREPLY', '*****@*****.**'), env('APP_NAME', 'Laravel'))->to($user->email)->subject('[' . env('APP_NAME') . '] ' . trans('messages.news_from_group_email_subject') . ' "' . $group->name . '"'); }); return true; } return false; } }
public function index(Request $request) { if ($request->has('query')) { $query = $request->get('query'); // build a list of public groups and groups the user has access to $my_groups = Auth::user()->groups()->orderBy('name')->get(); $my_groups_id = []; // using this array we can adjust the queries after to only include stuff the user has // might be a good idea to find a clever way to build this array of groups id : foreach ($my_groups as $the_group) { $my_groups_id[$the_group->id] = $the_group->id; } $public_groups = \App\Group::where('group_type', \App\Group::OPEN)->get(); $public_groups_id = []; // using this array we can adjust the queries after to only include stuff the user has // might be a good idea to find a clever way to build this array of groups id : foreach ($public_groups as $the_group) { $public_groups_id[$the_group->id] = $the_group->id; } $allowed_groups = array_merge($my_groups_id, $public_groups_id); $groups = \App\Group::where('name', 'like', '%' . $query . '%')->orWhere('body', 'like', '%' . $query . '%')->orderBy('name')->get(); $users = \App\User::where('name', 'like', '%' . $query . '%')->orWhere('body', 'like', '%' . $query . '%')->orderBy('name')->with('groups')->get(); $discussions = \App\Discussion::where('name', 'like', '%' . $query . '%')->orWhere('body', 'like', '%' . $query . '%')->whereIn('group_id', $allowed_groups)->orderBy('updated_at', 'desc')->with('group')->get(); $actions = \App\Action::where('name', 'like', '%' . $query . '%')->orWhere('body', 'like', '%' . $query . '%')->whereIn('group_id', $allowed_groups)->with('group')->orderBy('updated_at', 'desc')->get(); $files = \App\File::where('name', 'like', '%' . $query . '%')->whereIn('group_id', $allowed_groups)->with('group')->orderBy('updated_at', 'desc')->get(); $comments = \App\Comment::where('body', 'like', '%' . $query . '%')->with('discussion.group')->orderBy('updated_at', 'desc')->get(); // set in advance which tab will be active on the search results page $groups->class = ''; $discussions->class = ''; $actions->class = ''; $users->class = ''; $comments->class = ''; $files->class = ''; // the order of those ifs should match the order of the tabs on the results view :-) if ($groups->count() > 0) { $groups->class = 'active'; } elseif ($discussions->count() > 0) { $discussions->class = 'active'; } elseif ($actions->count() > 0) { $action->class = 'active'; } elseif ($users->count() > 0) { $users->class = 'active'; } elseif ($comments->count() > 0) { $comments->class = 'active'; } elseif ($files->count() > 0) { $files->class = 'active'; } return view('search.results')->with('groups', $groups)->with('users', $users)->with('discussions', $discussions)->with('files', $files)->with('comments', $comments)->with('actions', $actions)->with('query', $query); } }
@extends('layouts.app') @section('content') <div class="bs-example"> <div class="panel panel-primary"> <div class="panel-heading" style="background: #009FD7;"><h4 class="panel-title">{{ $team->name }}</h4></div> <div class="panel-body small-panel-body"> <table class="table table-bordered table-striped table-hover"> <th>Actions</th> <?php use App\Action; $actions = Action::where('owner', 'like', '%' . $team->name . '%')->get(); ?> @foreach($actions as $action) <tr> <td><a href="/actions/show/{{ $action->id }}">{{ $action->body }}</a></td> </tr> @endforeach <?php use App\Task; $tasks = Task::where('owner', 'like', '%' . $team->name . '%')->get(); ?> @if(count($tasks) > 0) <th>Tasks</th> @foreach($tasks as $task) <tr> <td><a href="/actions/show/{{ $task->id }}">{{ $task->body }}</a></td> </tr> @endforeach @endif
public function postStatus(Request $request) { //get id $pk = $request->pk; $col = 'status'; //get new success $value = $request->value; //Get action data row where success is stored if ($finditem = Action::where('id', $pk)->update([$col => $value])) { return \Response::json(array('status' => 1)); } else { return \Response::json(array('status' => 0)); } }
/** * @param \App\Offer $offer */ public function logBuy(\App\Offer $offer) { $action = \App\Action::where('title', '=', 'buy_offer')->get()->first(); $this->UserModel->actions()->attach($action->id, ['points' => $action->point, 'offer_id' => $offer->id]); $this->levelUpIfPossible(); }
/** * Renders a map of all users (curently) */ public function map() { $users = \App\User::where('latitude', '<>', 0)->get(); $actions = \App\Action::where('start', '>=', Carbon::now())->where('latitude', '<>', 0)->get(); $groups = \App\Group::where('latitude', '<>', 0)->get(); // randomize users geolocation by a few meters foreach ($users as $user) { $user->latitude = $user->latitude + mt_rand(0, 10) / 10000; $user->longitude = $user->longitude + mt_rand(0, 10) / 10000; } return view('dashboard.map')->with('users', $users)->with('actions', $actions)->with('groups', $groups)->with('latitude', 50.8503396)->with('longitude', 4.3517103); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $campaign = Campaign::find($id); $actions = Action::where('campaign_id', '=', $campaign->id)->groupBy('action')->select(\DB::raw('count(contact_id) as count, action'))->orderBy('count', 'DESC')->get(); return view()->make('campaigns.show')->with(['campaign' => $campaign, 'actions' => $actions]); }
@extends('layouts.app') @section('content') <div class="bs-example"> <div class="panel panel-primary"> <div class="panel-heading" style="background: #009FD7;"><h4 class="panel-title">{{ $user->name }}</h4></div> <div class="panel-body"> <?php use App\Action; use App\Task; use App\Department; use App\Team; $user_stuff = array(); $user_stuff = array_merge($user_stuff, Action::where('lead', 'like', '%' . $user->email . '%')->get()->all()); $user_stuff = array_merge($user_stuff, Action::where('collaborators', 'like', '%' . $user->email . '%')->get()->all()); $user_stuff = array_merge($user_stuff, Task::where('lead', 'like', '%' . $user->email . '%')->get()->all()); $user_stuff = array_merge($user_stuff, Task::where('collaborators', 'like', '%' . $user->email . '%')->get()->all()); $user_stuff = array_merge($user_stuff, Department::where('name', 'like', '%' . $user->department . '%')->get()->all()); ?> <table class="table table-striped table-hover table-bordered table-responsive"> <tbody> @foreach($user_stuff as $item) <?php $result_class = str_replace("app\\", "", strtolower(get_class($item))); ?> <tr> <td><a href="/{{ $result_class }}s/show/{{ $item->id }}">{{ ucwords($result_class) }}: @if(!in_array($result_class, ["department", "team"])){{ $item->body }}@else{{ $item->name }}@endif</a></td> </tr>
@extends('layouts.app') @section('content') <div class="bs-example"> <div class="panel panel-primary"> <div class="panel-heading" style="background: #009FD7;"><h4 class="panel-title">{{ $department->name }}</h4></div> <div class="panel-body small-panel-body"> <table class="table table-bordered table-striped table-hover"> <th>Actions</th> <?php use App\Action; $actions = Action::where('owner', 'like', '%' . $department->name . '%')->get(); ?> @foreach($actions as $action) <tr> <td><a href="/actions/show/{{ $action->id }}">{{ $action->body }}</a></td> </tr> @endforeach <th>Tasks</th> <?php use App\Task; $tasks = Task::where('owner', 'like', '%' . $department->name . '%')->get(); ?> @foreach($tasks as $task) <tr> <td><a href="/actions/show/{{ $task->id }}">{{ $task->body }}</a></td> </tr> @endforeach <th>Users</th> <?php
// Info user action $factory->defineAs(App\UserAction::class, 'info', function ($faker) use($factory) { $userAction = $factory->raw(\App\UserAction::class); $userAction['action_id'] = \App\Action::where('type', 'info')->first()->id; return $userAction; }); // Wrong format user action $factory->defineAs(\App\UserAction::class, 'wrong_format', function ($faker) use($factory) { $userAction = $factory->raw(\App\UserAction::class); $userAction['action_id'] = \App\Action::where('type', 'wrong_format')->first()->id; return $userAction; }); // Not allowed user action $factory->defineAs(\App\UserAction::class, 'not_allowed', function ($faker) use($factory) { $userAction = $factory->raw(\App\UserAction::class); $userAction['action_id'] = \App\Action::where('type', 'not_allowed')->first()->id; return $userAction; }); /** * Generate new offer. */ $factory->define(App\Offer::class, function ($faker) { $paymillOfferId = 'offer_' . substr(str_shuffle('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, 20); return ['paymill_offer_id' => $paymillOfferId, 'name' => $faker->word(), 'amount' => rand(2, 9999), 'interval' => '1 MONTH', 'currency' => 'EUR']; }); // Generate notification type $factory->define(App\NotificationType::class, function ($faker) { return ['type' => $faker->numerify('rand_####'), 'name' => $faker->name()]; }); // Generate notification $factory->define(\App\Notification::class, function ($faker) {
/** * Get actions that match given $userId. * * @param int $userId * @param bool $type * @return mixed */ private static function get($userId, $type = false) { $query = UserAction::where('user_id', $userId)->select('actions.name as name', 'actions.type as type', 'user_actions.id as id', 'user_actions.message as message', 'user_actions.created_at as created_at')->leftJoin('actions', 'user_actions.action_id', '=', 'actions.id'); // If $type is given, use in where condition if ($type) { $action = Action::where('type', $type)->select('id')->first(); $query->where('user_actions.action_id', $action->id); } return $query->orderBy('user_actions.created_at', 'desc')->paginate(); }
/** * Clears the given rule from all actions, action params and transformer mappings. * * @param Rule $rule */ private function clearRule(Rule $rule) { // delete all actions of rule // -> cascades down to actions_params Action::where("rule_id", $rule->rule_id)->delete(); // delete all transformer mappings of rule TransformerMapping::where("rule_id", $rule->rule_id)->delete(); }
public function explicitrf_function(SignalsRequest $request) { $username = $request->username; $device = $request->device_id; $video_id = $request->video_id; $action_type = $request->action; $explicit_rf = $request->value; //check if $request->score==-1 or 0 or 1 $record_exists = UserAction::where('username', $username)->where('video_id', $video_id)->where('action', $action_type)->first(); if (empty($record_exists)) { $user_action = new UserAction(['username' => $username, 'device_id' => $device, 'video_id' => $video_id, 'explicit_rf' => $explicit_rf, 'action' => $action_type]); $user_action->save(); $get_importance = Action::where('id', $request->action)->first(); $importance = $get_importance->importance; $user_action->update(array('weight' => $explicit_rf, 'importance' => $importance)); } else { $record_exists->update(array('explicit_rf' => $explicit_rf, 'weight' => $explicit_rf)); } //store in the dcgs table - only used for the online experiments $mecanex_user = MecanexUser::where('username', $username)->first(); $dcg_record = Dcg::where('mecanex_user_id', $mecanex_user->id)->where('video_id', $video_id); $dcg_record->update(array('explicit_rf' => $explicit_rf)); //////////////calculate ku/////////////////////// // number of all enrichments $video = Video::where('video_id', $video_id)->first(); $num_all_enrichments = DB::select(DB::raw('SELECT COUNT(*) as num FROM enrichments_videos_time WHERE video_id=?'), [$video->id]); $num_all_enrichments = $num_all_enrichments[0]->num; // create list with clicked enrichments $get_action_id = Action::where('action', 'click enrichment')->first(); $action_id = $get_action_id->id; $enrichment_click_ids = UserAction::where('username', $username)->where('video_id', $video_id)->where('action', $action_id)->get(array('content_id')); $num_clicked_enrichments = count($enrichment_click_ids); // replace all database entries with one with the appropriate weight (so that the calculation can be easily done). // The information for what enrichments where clicked is now in the $enrichment_click_ids variable if ($num_clicked_enrichments != 0) { DB::table('user_actions')->where('username', $username)->where('video_id', $video_id)->where('action', $action_id)->delete(); $user_action = new UserAction(['username' => $username, 'device_id' => $device, 'video_id' => $video_id, 'action' => $action_id, 'content_id' => '1']); $user_action->save(); $get_importance = Action::where('id', $action_id)->first(); $importance = $get_importance->importance; $user_action->update(array('weight' => $num_clicked_enrichments / $num_all_enrichments, 'importance' => $importance)); } // create list with shared enrichments $get_action_id = Action::where('action', 'share')->first(); $action_id = $get_action_id->id; $enrichment_share_ids = UserAction::where('username', $username)->where('video_id', $video_id)->where('action', $action_id)->get(array('content_id')); $num_shared_enrichments = count($enrichment_share_ids); // replace all database entries with one with the appropriate weight (so that the calculation can be easily done). // The information for what enrichments where clicked is now in the $enrichment_shared_ids variable if ($num_shared_enrichments != 0) { DB::table('user_actions')->where('username', $username)->where('video_id', $video_id)->where('action', $action_id)->delete(); $user_action = new UserAction(['username' => $username, 'device_id' => $device, 'video_id' => $video_id, 'action' => $action_id, 'content_id' => '1']); $user_action->save(); $get_importance = Action::where('id', $action_id)->first(); $importance = $get_importance->importance; $user_action->update(array('weight' => $num_shared_enrichments / $num_all_enrichments, 'importance' => $importance)); } $k_nominator = UserAction::where('username', $username)->where('video_id', $video_id)->groupBy('username')->get(['username', DB::raw('SUM(importance*weight) as total_score')])->first(); $query = "SELECT SUM(t1.importance ) AS total FROM (SELECT DISTINCT action, importance FROM user_actions WHERE username=:username AND video_id=:videoid) AS t1 "; $k_denominator = DB::select(DB::raw($query), array('username' => $username, 'videoid' => $video_id)); //returns array $k = $k_nominator->total_score / $k_denominator[0]->total; //to [0] gia na prospelasei to 1o stoixeio tou array pou einai to object /////////////////////////////update weights and update profile////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////Retrieve Terms///////////////////////////// //////////////retrieve terms for given video////////////// $video = Video::where('video_id', $request->video_id)->first(); $threshold = 0; //need to appropriate set $results = $video->term()->where('video_score', '>', $threshold)->get(array('term_id')); $video_term_list = []; foreach ($results as $result) { //retrieve the terms that will be updated array_push($video_term_list, $result->term_id); } sort($video_term_list); ///////////retrieve terms for the clicked enrichments////////////// // $get_actionid = Action::where('action', 'click enrichment')->first(); // $action_id = $get_actionid->id; // $enrichment_ids = UserAction::where('username', $username)->where('video_id', $video_id)->where('action', $action_id)->get(array('content_id')); $enrichment_term_list = []; // foreach ($enrichment_ids as $enrichment_id) // { // // //call the api and get some terms // //or emulate enrichment_terms // //$results=Enrichment::where('id',$enrichment_id)->get(array('term_id')) // foreach($results as $result) // { // array_push($enrichment_term_list,$result->term_id); // } // // } //$enrichment_terms=array_unique($enrichment_term_list); $enrichment_terms = [3, 4, 7]; //retrieve terms for the clicked ads $ads_terms = [4, 8, 10]; ///Final term_list - no need since I will update in three steps // $term_list=array_merge($video_term_list,$enrichment_terms,$ads_terms); // $terms=array_unique($term_list); ////////////////update weights of profile////////////////////////// $term_scores = []; //save all scores to get the max $user = MecanexUser::where('username', $username)->get()->first(); $video = Video::where('video_id', $video_id)->get()->first(); $link_user = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->get()->first(); //return $video; //return $link_user; //update based on video_terms //return $video_term_list; foreach ($video_term_list as $video_term_id) { $temp_user = $user->term->find($video_term_id); $user_term_score = $temp_user->pivot->user_score; //get score of user $temp_video = $video->term->find($video_term_id); $video_term_score = $temp_video->pivot->video_score; //get score of video $final_score = $k * (0.8 * $video_term_score); foreach ($enrichment_click_ids as $enrichment_click_id) { $id = $enrichment_click_id->content_id; $enrichment = Enrichment::where('enrichment_id', $id)->get()->first(); $temp_enrichment = $enrichment->term->find($video_term_id); $enrichment_term_score = $temp_enrichment->pivot->enrichment_score; $final_score = $final_score + $k * (0.1 / $num_clicked_enrichments * $enrichment_term_score); } foreach ($enrichment_share_ids as $enrichment_share_id) { $id = $enrichment_share_id->content_id; $enrichment = Enrichment::where('enrichment_id', $id)->get()->first(); $temp_enrichment = $enrichment->term->find($video_term_id); $enrichment_term_score = $temp_enrichment->pivot->enrichment_score; $final_score = $final_score + $k * (0.1 / $num_shared_enrichments * $enrichment_term_score); } //update score $new_score = $user_term_score + $final_score; //ok $new_score = max($new_score, 0); // don't let negative values array_push($term_scores, $new_score); // //store score $user->term()->sync([$video_term_id => ['user_score' => $new_score]], false); } //return $term_scores; // update matrix $number_video_terms = count($video_term_list); $link_term_scores = []; //save all scores to get the max for ($i = 0; $i <= $number_video_terms - 1; $i++) { for ($j = $i + 1; $j < $number_video_terms; $j++) { $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->where('term_home_id', $video_term_list[$i])->where('term_neighbor_id', $video_term_list[$j])->get()->first(); //return $temp_user_matrix; $temp_video = $video->term->find($video_term_list[$i]); $video_term_score1 = $temp_video->pivot->video_score; $temp_video = $video->term->find($video_term_list[$j]); $video_term_score2 = $temp_video->pivot->video_score; $final_score = $k * (0.8 * $video_term_score1 * $video_term_score2); foreach ($enrichment_click_ids as $enrichment_click_id) { $id = $enrichment_click_id->content_id; $enrichment = Enrichment::where('enrichment_id', $id)->get()->first(); $temp_enrichment = $enrichment->term->find($video_term_list[$i]); $enrichment_term_score1 = $temp_enrichment->pivot->enrichment_score; $temp_enrichment = $enrichment->term->find($video_term_list[$j]); $enrichment_term_score2 = $temp_enrichment->pivot->enrichment_score; $final_score = $final_score + $k * (0.1 / $num_clicked_enrichments * $enrichment_term_score1 * $enrichment_term_score2); } foreach ($enrichment_share_ids as $enrichment_share_id) { $id = $enrichment_share_id->content_id; $enrichment = Enrichment::where('enrichment_id', $id)->get()->first(); $temp_enrichment = $enrichment->term->find($video_term_list[$i]); $enrichment_term_score1 = $temp_enrichment->pivot->enrichment_score; $temp_enrichment = $enrichment->term->find($video_term_list[$j]); $enrichment_term_score2 = $temp_enrichment->pivot->enrichment_score; $final_score = $final_score + $k * (0.1 / $num_shared_enrichments * $enrichment_term_score1 * $enrichment_term_score2); } $new_score = $temp_user_matrix->link_score + $final_score; $new_score = max($new_score, 0); // don't let negative values array_push($link_term_scores, $new_score); $temp_user_matrix->link_score = $new_score; $temp_user_matrix->save(); } } //same should be done for enrichments and ads //find max value and divide term values $max_term_value = max(max($term_scores), 1); if ($link_term_scores != []) { $max_link_term_value = max(max($link_term_scores), 1); } foreach ($video_term_list as $video_term_id) { $temp_user = $user->term->find($video_term_id); $user_term_score = $temp_user->pivot->user_score; //get score of user $temp_video = $video->term->find($video_term_id); $video_term_score = $temp_video->pivot->video_score; //get score of video //update score $new_score = $user_term_score / $max_term_value; //ok //store score $user->term()->sync([$video_term_id => ['user_score' => $new_score]], false); } for ($i = 0; $i <= $number_video_terms - 1; $i++) { for ($j = $i + 1; $j < $number_video_terms; $j++) { $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->where('term_home_id', $video_term_list[$i])->where('term_neighbor_id', $video_term_list[$j])->get()->first(); $old_score = $temp_user_matrix->link_score; $new_score = $old_score / $max_link_term_value; $temp_user_matrix->link_score = $new_score; $temp_user_matrix->save(); } } //calculate profile $terms = Term::all()->count(); for ($j = 1; $j <= $terms; $j++) { $profile_score = 0; for ($i = 1; $i <= $terms; $i++) { $temp_user = $user->term->find($i); $user_term_score = $temp_user->pivot->user_score; //get score of user if ($i == $j) { $link_score = 0; } elseif ($i > $j) { $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->where('term_home_id', $j)->where('term_neighbor_id', $i)->get()->first(); $link_score = $temp_user_matrix->link_score; } else { $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->where('term_home_id', $i)->where('term_neighbor_id', $j)->get()->first(); $link_score = $temp_user_matrix->link_score; } $profile_score = $profile_score + $user_term_score * $link_score; } $user->profilescore()->sync([$j => ['profile_score' => $profile_score]], false); } DB::table('user_actions')->where('username', $username)->where('video_id', $video_id)->delete(); $response = ["message" => 'RF Saved']; $statusCode = 200; return response($response, $statusCode)->header('Content-Type', 'application/json'); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $touch = Touch::find($id); $actions = Action::where('touch_id', '=', $touch->id)->groupBy('action')->select(\DB::raw('count(contact_id) as count, action'))->orderBy('count', 'DESC')->get(); return view()->make('touches.show')->with(['touch' => $touch, 'actions' => $actions]); }
/** * Delete user actions. * * @param int $userId * @param string $type * @param DeleteUserActionsRequest $request * @return mixed */ public function deleteUserActions($userId, $type, DeleteUserActionsRequest $request) { $response = new AjaxResponse(); // Make sure user id exists if (!User::where('id', $userId)->count()) { $response->setFailMessage(trans('users_manager.user_not_found')); return response($response->get(), $response->badRequest())->header('Content-Type', 'application/json'); } $typeUsedInQuery = false; if ($type === 'allowed' || $type === 'info' || $type === 'wrong_format' || $type === 'not_allowed') { $typeUsedInQuery = $type; } // Delete user actions if (!$typeUsedInQuery) { UserAction::where('user_id', $userId)->delete(); } else { $action = Action::where('type', $type)->first(); UserAction::where('user_id', $userId)->where('action_id', $action->id)->delete(); } $response->setSuccessMessage(trans('users_manager.user_actions_deleted')); return response($response->get())->header('Content-Type', 'application/json'); }
public function generate($id) { ini_set("max_execution_time", 0); $project = Project::find($id); $accomplishments = Accomplishment::where('project_id', $id)->get(); $actions = Action::where('project_id', $id)->get(); $expenses = Expense::where('project_id', $id)->get(); $issues = Issue::where('project_id', $id)->get(); $milestones = Milestone::where('project_id', $id)->get(); $risks = Risk::where('project_id', $id)->get(); $lastUser = $project->users->last(); return view('projects.generate', compact('project', 'actions', 'accomplishments', 'expenses', 'issues', 'milestones', 'risks', 'lastUser')); }
public function rf(Request $request) { $user = Auth::user(); $username = $user->username; $device = "1"; $video_id = $request->video_id; $action_type = 6; $explicit_rf = $request->score; //check if $request->score==-1 or 0 or 1 $record_exists = UserAction::where('username', $username)->where('video_id', $video_id)->where('action', $action_type)->first(); if (empty($record_exists)) { $user_action = new UserAction(['username' => $username, 'device_id' => '1', 'video_id' => $video_id, 'explicit_rf' => $explicit_rf, 'action' => $action_type]); $user_action->save(); $get_importance = Action::where('id', $action_type)->first(); $importance = $get_importance->importance; $user_action->update(array('weight' => $explicit_rf, 'importance' => $importance)); // return $record_exists; } else { $record_exists->update(array('explicit_rf' => $explicit_rf, 'weight' => $explicit_rf)); } //store in the dcgs table - only used for the online experiments $mecanex_user = MecanexUser::where('username', $username)->first(); $dcg_record = Dcg::where('mecanex_user_id', $mecanex_user->id)->where('video_id', $video_id); $dcg_record->update(array('explicit_rf' => $explicit_rf)); //////////////calculate ku/////////////////////// $k_nominator = UserAction::where('username', $username)->where('video_id', $video_id)->groupBy('username')->get(['username', DB::raw('SUM(importance*weight) as total_score')])->first(); //prepei edw na to diairw k me to plithos twn sunolikwn enrichments k ads $query = "SELECT SUM(t1.importance ) AS total FROM (SELECT DISTINCT action, importance FROM user_actions WHERE username=:username AND video_id=:videoid) AS t1 "; $k_denominator = DB::select(DB::raw($query), array('username' => $username, 'videoid' => $video_id)); //returns array $k = $k_nominator->total_score / $k_denominator[0]->total; //to [0] gia na prospelasei to 1o stoixeio tou array pou einai to object /////////////////////////////update weights and update profile////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////Retrieve Terms///////////////////////////// //////////////retrieve terms for given video////////////// $video = Video::where('video_id', $video_id)->first(); $threshold = 0.1; //need to appropriate set $results = $video->term()->where('video_score', '>', $threshold)->distinct()->get(array('term_id')); //$results = $results->unique(); //return $results; $video_term_list = []; foreach ($results as $result) { //retrieve the terms that will be updated array_push($video_term_list, $result->term_id); } sort($video_term_list); //return $video_term_list; ///////////retrieve terms for the clicked enrichments////////////// $get_actionid = Action::where('action', 'click enrichment')->first(); $action_id = $get_actionid->id; $enrichment_ids = UserAction::where('username', $username)->where('video_id', $video_id)->where('action', $action_id)->get(array('content_id')); $enrichment_term_list = []; // foreach ($enrichment_ids as $enrichment_id) // { // // //call the api and get some terms // //or emulate enrichment_terms // //$results=Enrichment::where('id',$enrichment_id)->get(array('term_id')) // foreach($results as $result) // { // array_push($enrichment_term_list,$result->term_id); // } // // } //$enrichment_terms=array_unique($enrichment_term_list); // $enrichment_terms = [3, 4, 7]; //retrieve terms for the clicked ads // $ads_terms = [4, 8, 10]; ///Final term_list - no need since I will update in three steps // $term_list=array_merge($video_term_list,$enrichment_terms,$ads_terms); // $terms=array_unique($term_list); ////////////////update weights of profile////////////////////////// $term_scores = []; //save all scores to get the max $user = MecanexUser::where('username', $username)->get()->first(); $video = Video::where('video_id', $video_id)->get()->first(); $link_user = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->get()->first(); //return $link_user; //update based on video_terms foreach ($video_term_list as $video_term_id) { $temp_user = $user->term->find($video_term_id); $user_term_score = $temp_user->pivot->user_score; //get score of user $temp_video = $video->term->find($video_term_id); $video_term_score = $temp_video->pivot->video_score; //get score of video //update score $new_score = $user_term_score + $k * (0.8 * $video_term_score); //ok $new_score = max($new_score, 0); // don't let negative values array_push($term_scores, $new_score); // //store score $user->term()->sync([$video_term_id => ['user_score' => $new_score]], false); } // update matrix $number_video_terms = count($video_term_list); $link_term_scores = []; //save all scores to get the max for ($i = 0; $i <= $number_video_terms - 1; $i++) { for ($j = $i + 1; $j < $number_video_terms; $j++) { $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->where('term_home_id', $video_term_list[$i])->where('term_neighbor_id', $video_term_list[$j])->get()->first(); //return $temp_user_matrix; $temp_video = $video->term->find($video_term_list[$i]); $video_term_score1 = $temp_video->pivot->video_score; $temp_video = $video->term->find($video_term_list[$j]); $video_term_score2 = $temp_video->pivot->video_score; //return $temp_user_matrix; $new_score = $temp_user_matrix->link_score + $k * (0.8 * ($video_term_score1 * $video_term_score2)); $new_score = max($new_score, 0); // don't let negative values array_push($link_term_scores, $new_score); $temp_user_matrix->link_score = $new_score; $temp_user_matrix->save(); } } //same should be done for enrichments and ads //find max value and divide term values $max_term_value = max(max($term_scores), 1); if ($link_term_scores != []) { $max_link_term_value = max(max($link_term_scores), 1); } foreach ($video_term_list as $video_term_id) { $temp_user = $user->term->find($video_term_id); $user_term_score = $temp_user->pivot->user_score; //get score of user $temp_video = $video->term->find($video_term_id); $video_term_score = $temp_video->pivot->video_score; //get score of video //update score $new_score = $user_term_score / $max_term_value; //ok // //store score $user->term()->sync([$video_term_id => ['user_score' => $new_score]], false); } for ($i = 0; $i <= $number_video_terms - 1; $i++) { for ($j = $i + 1; $j < $number_video_terms; $j++) { $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->where('term_home_id', $video_term_list[$i])->where('term_neighbor_id', $video_term_list[$j])->get()->first(); $old_score = $temp_user_matrix->link_score; $new_score = $old_score / $max_link_term_value; $temp_user_matrix->link_score = $new_score; $temp_user_matrix->save(); } } //calculate profile $terms = Term::all()->count(); for ($j = 1; $j <= $terms; $j++) { $profile_score = 0; for ($i = 1; $i <= $terms; $i++) { $temp_user = $user->term->find($i); $user_term_score = $temp_user->pivot->user_score; //get score of user if ($i == $j) { $link_score = 0; } elseif ($i > $j) { $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->where('term_home_id', $j)->where('term_neighbor_id', $i)->get()->first(); $link_score = $temp_user_matrix->link_score; } else { $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->where('term_home_id', $i)->where('term_neighbor_id', $j)->get()->first(); $link_score = $temp_user_matrix->link_score; } $profile_score = $profile_score + $user_term_score * $link_score; } $user->profilescore()->sync([$j => ['profile_score' => $profile_score]], false); } DB::table('user_actions')->where('username', $username)->where('video_id', $video_id)->delete(); return Redirect::route('home')->with('message', 'Thank you for watching the video'); }