I´m creating a project in jhipster and I need to access to this metrics and structure:
Structure:
Of the players we want to save:
Nickname (unique) can only be formed by: letters, numbers and underscore.
Name
Surname
Date of birth
Secondly, we must create the necessary structure to host the games.
For each game played we want to save:
Player who has won the game
Player who has lost the game
Number of points of the winner
Game played
Metrics:
For a specific player, whose nickname must be provided, list of
games won.
For a given player, number of games won.
List of players who have won playing a given game.
My problem is that the list of players to match with the list of winner and losers and right now this is not happening. The is a list of players with nickname etc and a different one not related of winners and losers.
How can I create the relationship in this case?
This is my code so far in JDL-Studio. It doesn´t work.
entity Player {
nickname String unique pattern(/[a-zA-Z0-9_]+/),
name String,
surname String,
dateOfBirth LocalDate
}
entity Game {
winnerPoints Integer,
loser String,
winner String,
game String
}
relationship ManyToMany {
Game{player(nickname)} to Player{game}
}
Relationship Jhipster
Winner and loser should not be strings, they should be 2 relationships to Player.
Also it seems strange that Game entity has a game field, either the entity is badly named or it's the field.
entity Player {
nickname String unique pattern(/[a-zA-Z0-9_]+/),
name String,
surname String,
dateOfBirth LocalDate
}
entity Game {
winnerPoints Integer,
game String
}
relationship ManyToOne {
Game{winner(nickname)} to Player,
Game{loser(nickname)} to Player
}
Regarding the last question, try making the relationship required:
relationship ManyToOne {
Game{winner(nickname) required} to Player,
Game{loser(nickname) required} to Player
}
Related
im a new computer science student and ive been tasked to do a code following this intructions:
In this exercise they must build a program that allows collecting the most frequent destinations for a Taxi company and the most frequent stations for a Bus company.
To meet this requirement you must create a program that receives the name of the company and the number of frequent places, then you must receive the frequent places indicated by the user and store that data in a CTaxi class and another CBus class according to the attributes and methods specified below:
CTaxi
----------
name: string
places: string
CTaxi()
CTaxi (_name, destinations)
~CTaxi()
getName()
getAmountPlaces()
getPlace(position)
CBus
----------
name: string
places: string
CBus()
CBus (_name, stations)
~CBus()
getName()
getAmountPlaces()
getPlace(position)
So the input is:
Uber (taxi company)
3
J.F.k airport
World Trade Center
China Town
Bigbus (bus company)
2
Manhattan
Brooklyn
How can i start with this code??
I would like to know how the PersonID string (obtained after a call to the PersonGroup Person – Create method of the Face API) is computed. In particular, I would like to know if any information (such as the fields “name” and “userData” for example) can be recovered from it without calling the specific API function Person Group Person – Get.
Thanks in advance.
PersonID string is just a GUID here . If you create a persion, Azure Face service will provide you with an GUID as the ID of that person. As an identifier , PersonID has none business with person details such as “name” and “userData” .
If you want to get some info of a persion , I am afraid using API function Person Group Person – Get is the only way .
If you mean getting the information back that you put into the create() method parameters, yes you can get that from the client.person_group_person.create() results.
The create() method of PersonGroupPerson has the following fields as parameters: person_group_id, name, user_data, custom_headers, raw, and operation_config. So you can add values to those when you create a new PersonGroupPerson. Once this method is called, a Person object is returned with these properties: name, user_data, person_id, persisted_face_ids. So for example, this is what you could do:
# Create a new Person object and add that image to it.
new_person = client.person_group_person.create(person_group_id, name)
img = open(image_name, 'rb')
# Add the new person to your Person object and your person group
face_client.person_group_person.add_face_from_stream(person_group_id, new_person.person_id, img)
print('New Person Created:', new_person.name)
In the above example, you get person_id and name from the results of your create() call. So, whatever parameters you add in create(), can be retrieved from the result.
However, this is just general Person information, you have not yet added images (faces) of this person to this Person object yet, unless you call add_face_from_stream() or add_face_from_url().
If you are wondering how the person ID is created, Microsoft has some of their source code available in Github.
Person Group Person operations: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/cognitiveservices/azure-cognitiveservices-vision-face/azure/cognitiveservices/vision/face/operations/_person_group_person_operations.py
Person class (line 1213): https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/cognitiveservices/azure-cognitiveservices-vision-face/azure/cognitiveservices/vision/face/models/_models.py
I want to random pick an item from a list. This is no problem, but the size is worrying me.
I have a sort of lottery game where a user can buy one or multiple tickets. Each ticket is a chance to win. I need to draw some players from the list.
So I thought I am going to build a list like:
//loop over all the players
for loop
get the number of tickets
loop over the number of tickets
insert the user x times into an array
So when the user has 10 tickets, he is going to saved 10x in the array. So I can randomly draw someone from that list. But the problem is, I have around 1600 users with each 200k tickets or more.
What is the best way to do this?
Why not use a json object as
{ "players" : [ { "player": id , "ticketsNu" : num } .... ]
"totalNu" : numb }
When it comes to choosing the winning ticket, then you have to calculate each players chances as
players.forEach((player)=>{ player.chances = player.tiketsNu / players.totalNu })
I am preloading data on an app's first launch into Core Data, need to point to objects yet to be instantiated and can't figure out how to do this. I saw a similar question, though the solution isn't applicable in this situation.
Say I have 3 classes
class Person {
var nationOfBirth: Nation
...
}
class City {
var mayor: Person
...
}
class Nation {
var capitalCity: City
...
}
If i am loading an initial data set of nations, then cities, then people (or any other order) then no matter which order I load them in I will need to set instances yet to be instantiated (though I know they will be) and I'm struggling to figure out how to do this and will appreciate any help
One of this fields must be optional, because in your example you have cycle references. Also Optional field in this case must have week reference for another field to clear memory correctly in the end. Your code:
class Person {
var nationOfBirth: Nation
init(nation: Nation) {
nationOfBirth = nation
}
}
class City {
var mayor: Person
init(person: Person) {
mayor = person
}
}
class Nation {
weak var capitalCity: City?
}
//initialization
let nation = Nation()
let person = Person(nation: nation)
let city = City(person: person)
nation.capitalCity = city
In swift if you are declaring field in class without default initialisation you must initialise it in constructor(init). In your case you have 3 classes, each with one field of another class without default initialisation. So you need to initialise then in init method.
To initialise Person you need object of Nation, to initialise Nation you need object of City, to initialise City you need object of Nation, and again you need object of Person, than City, than Nation. As you you see it is infinity loop.
To solve this problem you need to break this loop. You can do it only with setting field of One class as optional (with ? in the end of type). After that you don't need to initialise that field in initialiser, because now it can contain nil(nothing).
If you don't need to initialise it in initialiser, you can now create member of class with optional field without object of another class and just set it in the end. In my code you can see, that City field in Nation is set as optional, so i can create member of Nation without initial City value(let nation = Nation()).
After that, as i have member of class Nation, i can create Person with initialiser that takes Nation object(let person = Person(nation: nation)).
In the same way as now we have created member of person we can create member of city(let city = City(person: person)).
In the end we have member of city, so we can set it to nation object, that was created at the beginning without city(nation.capitalCity = city).
About why we need weak reference in this case you can read hear - https://developer.apple.com/library/ios/documentation/swift/conceptual/swift_programming_language/AutomaticReferenceCounting.html#//apple_ref/doc/uid/TP40014097-CH20-XID_92
I'm vainly attempting to learn how to use object databases. In database textbooks the tradition seems to be to use the example of keeping track of students, courses and classes because it is so familiar and applicable. What would this example look like as an object database? The relational database would look something like
Student
ID
Name
Address
Course
ID
Name
PassingGrade
Class
ID
CourseID
Name
StartTime
StudentClass
ID
ClassID
StudentID
Grade
Would you keep StudentClasses inside of Classes which is, in turn, inside Course and then keep Student as a top level entity?
Student
ID
Name
Address
Course
ID
Name
Classes[]
Name
StartTime
Students[]
StudentID
So you have Courses, Students and Classes, which are parts of Courses and visited by Students? I think the question answers itself if you think about it. Maybe it's clearer if you go away from the pure JSON of MongoDB and look at how you would define it in an ODM (the equivalent of an ORM in RDBs) as document based DBs don't really enforce schemas of their own (example is based on MongoEngine for Python):
class Student(Document):
name = StringField(max_length=50)
address = StringField()
class Attendance(EmbeddedDocument):
student = ReferenceField(Student)
grade = IntField(min_value=0, max_value=100)
class Class(EmbeddedDocument):
name = StringField(max_length=100)
start_time = DateTimeField()
attendance_list = ListField(EmbeddedDocumentField(Attendance))
class Course(Document):
name = StringField(max_length=100)
classes = ListField(EmbeddedDocumentField(Class))
This would give you two collections: one for Students and one for Courses. Attendance would be embedded in the Classes and the Classes would be embedded in the Courses. Something like this (pseudocode):
Student = {
name: String,
address: String
}
Course = {
name: String,
classes: {
name: String,
start_time: DateTime,
attendance_list: {
student: Student,
grade: Integer
}[]
}[]
}
You could of course put the grade info in the student object, but ultimately there really isn't much you can do to get rid of that extra class.
The whole point of an OODBMS is to allow you to design your data model as if it were just in memory. Don't think of it as a database schema problem, think of it as a data modelling problem on the assumption that you have a whole lot of VM and a finite amount of physical memory, You want to make sure that you don't have to boil an ocean of page faults (or, in fact, database I/O operations) to do the operations that are important.
In a pure OODB, your model is fine.