Get all the actors that played in a movie that all my friends liked - titan

I am playing with TinkerPop and I am getting my head stuck around this problem : I would like to find all the actors from the movies that ALL my friends liked (in other words, find the common movies that my friends liked and get the name of all the actors that played in those movies)
so far what I tried :
g.V(v1).out("friend").out("like").in("play_in").values("name")
returns all the actors that played in a movie that at least ONE of my friends liked. I am quite new to TinkerPop and the vast API confuses me somehow.
Thanks !

As always, let's start with a sample graph:
g = TinkerGraph.open().traversal()
g.addV(id, "user 1").as("u1").
addV(id, "user 2").as("u2").
addV(id, "user 3").as("u3").
addV(id, "movie 1").as("m1").
addV(id, "movie 2").as("m2").
addV(id, "movie 3").as("m3").
addE("friend").from("u1").to("u2").
addE("friend").from("u1").to("u3").
addE("like").from("u2").to("m1").
addE("like").from("u2").to("m2").
addE("like").from("u3").to("m2").
addE("like").from("u3").to("m3").iterate()
As you can already see, only movie 2 was liked by all friends of user 1. The traversal to answer the question follows (with comments inline):
gremlin> g.V("user 1"). /* start at user 1 */
out("friend").aggregate("friends"). /* collect all his friends */
out("like").dedup(). /* traverse to all the movies they liked */
filter(
__.in("like").where(within("friends")).count().as("a"). /* count the number of friends who liked the movie */
select("friends").count(local).where(eq("a")) /* compare to the number of total friends and */
) /* filter, if the counts don't match */
==>v[movie 2]
Now, if you want to get the actors names, you only need to append:
.in("play_in").dedup().values("name")

Related

gRPC repeated field vs stream

Hi im currently looking into grpc and im curious about the use usage of a repeated field vs a stream.
For example let's say i want to implement a reservation service for movie seats. The issue im facing is, that i want to inform the service for which movie i want to reserve the seats for.
I can think of 2 solutions, first:
I send the id of the movie with every seat i want to reserve, or with oneof at the beginning of the stream
like this:
rpc ReserveSeatsForShowing(stream SeatReservationRequest) returns(Reservation);
message SeatReservationRequest{
oneof reservationOneOf{
int32 showingId = 1;
SeatReservation seatReservation = 2;
}
}
Or using a repeated field like this
rpc ReserveSeatsForShowing(SeatReservationRequest) returns(Reservation);
message SeatReservationRequest{
int32 showingId = 1;
repeated SeatReservation seatReservation = 2;
}
Since i haven't really worked with grpc before im not quite sure which option to choose or if other options are available.
Looking forward for your recommendations
For the seat reservation, I think it would make sense to use repeated field. Just like real world scenario, the request is like "I want seat A, B, C for movie X", which is more like repeated manner than streaming. thus, the payload is very small. Also, this way should use less server resource since it is a batch process.

How to count how many times checked if answer correct "Swift"

I am trying a tutorial on how to do a number guessing game in Swift and we have where you put a number in a field and click a button to guess. If you are wrong a message appears and if you are right a different message appears. I would like to count how many times someone tried to answer the question and if they get to 5 times trying I would like to reply with a message like you stink at this (kidding)"Don't give up!" or whatever. Is there a way to count how many times someone has clicked that button. I see some similar posts but nothing that helps..
Declare a variable var count:Int = 0
And then every time you click the button, where you check is it match, add
count = count + 1
and then see when you gonna reply them the message, use if else
if count == 5{
// Any message
}

What metadata keys are available in Everyplay?

On the Everyplay Unity3D guide page these three lines are given as an example of using metadata with Everyplay.
Everyplay.SharedInstance.SetMetadata("level", levelNumber);
Everyplay.SharedInstance.SetMetadata("level_name", levelName);
Everyplay.SharedInstance.SetMetadata("score", score)
Are there any other metadata keys available than those three? Can you define your own metadata for your game instead of just using predefined keys? Could not find any more documentation on this than the above mentioned example.
You can and should provide as much metadata about the video as you can as there are several features to use the data already under work. The metadata supplied with the video has several intended (future) purposes. Currently only score and level_name are displayed with the videos on Everyplay (for example: http://everyplay.com/videos/8106 ).
The developer can (in the near future) configure what metadata to show with the videos, a racing game could show time, circuit and laps and an FPS game might show kills and deaths. Also we are already developing features into our API to allow developers to use the metadata to query existing videos, for example fetching a list of videos from level 1 in the past 10 days sorted by "score" and so on.
For a quick example here is the metadata that stair dismount (the video in the link above) provided with the same video:
metadata: {
somersaults: 1,
level: 60,
decapitation: false,
bifurcation: false,
push_force_z: -3957.182,
push_force_y: 1773.326,
distance: -1,
push_pos_z: 8.371746,
push_force_x: -1675.732,
push_pos_y: 24.18944,
push_body_name: "LeftForearm",
ragdoll_custom_face: true,
push_pos_x: -0.6025434,
push_body_id: 2189472344,
leaderboard_id: 1208019,
score: 3802645,
level_name: "Revolting Doors",
ragdoll_breakability: false,
distance_leaderboard_id: 0,
ragdoll_name: "Mr. Dismount",
ragdoll: 0
}

Episerver, getting a users current "work-item"

I want to make a gadget that lists all the users with their current workitems shown.
How do I get the current work item which is shown in the page-tree in editor-mode. For example, when user 1 works with page 1 you can see that there is a little person-icon next to the name and if you hoover over it, it will say user 1.
Although it is possible to loop all pages in the page-tree and get latest changes, but that would be tough on the server.
There is an API for the notifications. Try this:
using EPiServer.Editor.Notification;
InUseNotificationRepository pagesInUseRepo = new InUseNotificationRepository();
var notifications = pagesInUseRepo.GetAllInUseNotifications();
foreach (var notification in notifications)
{
// notification.PageGuid
}

asp.net mvc 2: online user

In asp.net mvc2, how do I show the status of a user as "online"?
So if the user is actively working on the site, the status would be "online".
if the user stepped away from the site for about 5 minutes then it would be "5 minutes".
if the user stepped away from the site for about 10 minutes then it would be "10 minutes".
So on and so forth.
What is the best way to accomplish this? Any code sample would be very helpful to me.
The responses so far suggest that I used Ajax. If so, then how would I be able to query online users vs offline users. All my queries go against Database. Is it possible to query and display results joining Ajax results with Database queries?
I would think the most straight forward way of doing it would be with a session variable. You could add a line to your controllers (either in the action method, or the constructor, or even possibly with an action filter) which stashes the current Date/Time in the session. You could then use an ajax call to update the value on the screen at a specific interval. You would probably want to make the interval in minutes rather than seconds otherwise you would be displaying a counter (i.e. "1 second", "2 seconds", etc).
Some quick code samples:
// Somewhere in controller
Session["LastSeen"] = DateTime.Now;
// Now, an action that would return the amount of time since the user was last seen
public ViewResult GetLastSeenTime()
{
return Json(new { TimeAway = Date.Time.Now.Subtract((DateTime)Session["LastSeen"]).TotalMinutes});
}
// Then on your page, something like this
$.post("/Controller/GetLastSeenTime",null,function(result) {
if(result.LastSeen < 5)
$("#Status").Text("Online");
else if (result.LastSeen % 10 == 0)
$("#Status").Text(result.LastSeen + " minutes");
},"json");
Totally not tested, but should be close.
ckramer is right. I suggest expending his solution to make it js degradable.
/ Now, an action that would return the amount of time since the user was last seen
public ActionResult GetLastSeenTime()
{
if (Request.IsAjax) {
return Json(new { TimeAway = Date.Time.Now.Subtract((DateTime)Session["LastSeen"]).TotalMinutes});
}
ViewData.Add("LastSeen", Date.Time.Now.Subtract((DateTime)Session["LastSeen"]).TotalMinutes}));
return View("MyView")
}