I am updating an application I've written used by my employer, a University, to allow students to register for their desired residence hall.
I'm working on a new feature that will allow students to "partner" with another student - so that when one or the other registers for a room, the other student will be registered as well.
Now, let us say we have John Doe and James Doe - and they partner with each other for room registration. The time when students is staggered based on their current class level. I need a way to determine (without a billion IF..THEN statements) which student has the lower class level. The values for class level are FR, SO, JR, SR, 5SR (from most junior to most senior).
In the above example, John Doe might be a FR while James Doe may be a SR. Neither James nor John should be allowed to register until FR's are allowed to register - since that is the partnerships "base" class level.
Essentially I want to do something like:
IF John_Doe_Class_Level < James_Doe_Class_Level Then
Partnership_Class_Level = John_Doe_Class_Level
Else
Partnernship_Class_Level = James_Doe_Class_Level
End If
Any idea how to accomplish this effectively?
Where do you define your class levels? If it is in the code, use enums with associated numeric values.
Public Enum ClassLevel As Integer
FR = 0
SO = 1
JR = 2
End Enum
Public Class Student
Public Property Name As String
Public Property Level As ClassLevel
End Class
Public Sub TestIt(ByVal studentA As Student, ByVal studentB As Student)
If studentA.Level > studentB.Level Then
' dostuff
End If
End Sub
I know I'm clearly missing something, but if you assign these class levels to an enum, why wouldn't the above work?
public enum ClassLevel
{
FR=1,
SO=2,
JR=2,
SR=3,
5SR=4
}
etc
IF John_Doe.ClassLevel < JamesDoe.Class_Level Then
Partnership.Class_Level = John_Doe.ClassLevel
Else
Partnernship.Class_Level = James_Doe.ClassLevel
End If
I would run the values through function that returns a number then compare those values to each other. Something like...
IF numericClassLevel(John_Doe_Class_Level) < numericClassLevel(John_Doe_Class_Level) Then
Partnership_Class_Level = John_Doe_Class_Level
Else
Partnernship_Class_Level = James_Doe_Class_Level
End If
public function numericClassLevel(strClassLevel) as integer
select case strLevel
case "FR"
return 1
etc.
end select
end function
Related
I am still learning about python and I face some trouble extracting data from a dict. I need to create a loop which check each values and extract the keys. So for this code I need to find the nice students. I am stuck at line 3 #blank.
How do i go about this?
Thanks in advance
class = {"James":"naughty", "Lisa":"nice", "Bryan":"nice"}
for student in class:
if #blank:
print("Hello, "+student+" students!")
else:
print("odd")
Uses dictionary methods "keys(), values(), items()":
def get_students_by_criteria(student_class, criteria):
students = []
for candidate, value in student_class.items():
if value == criteria:
students.append(candidate)
return students
my_class = {"James":"naughty", "Lisa":"nice", "Bryan":"nice"}
print(get_students_by_criteria(my_class, "nice"))
Warning to the word "class" it is a keyword reserved for python programming oriented object
I'm totally stuck on this. I hope some expert here can help me out.
I have a page that lists survey results. The user has to guess the top 3 breeds of a dog. Then, the results are shown. Important: the user is guessing the TOP 3 breeds of the dog and they can be in any order.
For example, the user is shown a photo of a dog and underneath the photo is a list of three dropdowns:
Dropdown_1 Dropdown_2 Dropdown_3
Each of these dropdowns contains the same list of breeds, such as Beagle, German Shepard, Pug, etc. The user then selects one (and only one) breed for each of the dropdowns.
So, in the example above, the user would select:
German Shepard Beagle Pug
Now, when the answer/response page is displayed, they will see if their guesses match the correct answers.
Obviously, it would be easy to write something like:
If (BreedChoice1 = BreedChoice1Answer And BreedChoice2 = BreedChoice2Answer And BreedChoice3 = BreedChoice3Answer) Or
(BreedChoice1 = BreedChoice1Answer And BreedChoice2 = BreedChoice3Answer And BreedChoice3 = BreedChoice2Answer) Or
(BreedChoice1 = BreedChoice2Answer And BreedChoice2 = BreedChoice1Answer And BreedChoice3 = BreedChoice3Answer) Or
(BreedChoice1 = BreedChoice2Answer And BreedChoice2 = BreedChoice3Answer And BreedChoice3 = BreedChoice1Answer) Or
(BreedChoice1 = BreedChoice3Answer And BreedChoice2 = BreedChoice1Answer And BreedChoice3 = BreedChoice2Answer) Or
(BreedChoice1 = BreedChoice3Answer And BreedChoice2 = BreedChoice2Answer And BreedChoice3 = BreedChoice1Answer) Then
Response.Write("You Guessed ALL breeds correctly!")
End If
But how would I display message they says: "You guessed two breeds correctly". And one that says "You guessed one breed correctly"?
Remember that choice 1, 2, and 3 can match the answers 1, 2 and 3 in any order.
Any advice would be appreciated! Thank you in advance.
-- Chris
To solve this it would be simplest to use an Intersect method and to section up your code a little differently.
Firstly I would suggest that we put the "answers" into a list rather than keep them as separate variables (since you suggest they can be in any order). Then you should put your submitted answers also into a collection.
You can then do a very simple Intersect to get a collection that contains the elements common to both:
List<string> breeds = new List<string>() { "Beagle", "German Shepard", "Pug" };
List<string> choices = new List<string>() { "Beagle", "Pug", "Greyhound" };
int correctAnswers = breeds.Intersect(choices).Count();
The int "correctAnswers" then tells you how many they got right. (Obviously if you are using something more complicated than a string, such as a custom "Breed" class, for the breeds you could use some Linq to check the breed name property).
You could then use a neat bit of string interpolation (the $ sign in front of the string declaration) to get your result message:
$"Congratulations, you guessed {correctAnswers} breeds correctly!";
Hope his helps!
================
| Person |
|--------------|
|- id : String |
|--------------|
================
I have class Person with property id that is String type. I have to check that id is a number that contains 11 digits. I thinking about something like this:
context Person::id:String
inv: self.id->forAll(l|l.oclIsTypeOf(Integer))
and
self.id.size() = 11
but I have feeling that is not correct.
EDIT.
Now im sure it's not correct,
l.oclIsTypeOf(Integer) always return false, because is oclIsTypeOf should be only called on OclAny, when id is a String type.
EDIT 2. (Solution)
I solved it like this:
context Person::id:String
inv: not self.id.toInteger().oclIsInvalid()
and
self.id.size() = 11
Solution provided by Vincent Aranega below should works too
There is not so much methods on String, but the toInteger one can help you there. It returns the Integer value of a String or Invalid if the string cannot be converted to an Integer. So:
context Person::id:String
inv: not self.id.toInteger().oclIsUndefined()
and self.id.size() = 11
should do the trick! (tested with success in Acceleo)
I have an employee parent-child hierarchy in a dimension called Employees which shows the managerial structure of an organisation. This hierarchy is [Employees].[Managerial].
There is another hierarchy that lists all the employees for an organisation. This is a single level hierarchy and it is [Employess].[All Employees].
I have a query that looks something like this:
With
Member measures.[FullTimeSalary] as measures.[Salary] * measures.[FullTimeFactor]
Select {measures.[FullTimeSalary]} on 0,
Non empty
{
[Employess].[All Employees].[All].Children
}
On 1
From MyCube
Where ([Time].[Month].&[201501])
Now if I expand the parent-child hierarchy (the [Employees].[Managerial] hierarchy) I can see each of the different levels of this structure( [Level 02], [Level 03], [Level 04], ect) and what I need to do now is create a new calculated measure called measures.[SupervisingManager] that brings back the currentmembers value at [Level 03] of the hierarchy.
I've tried
member measures.[SupervisingManager] as [Employees].[Managerial].[Level 03].currentmember.member_name
but that just returns "#Error" and using
member measures.[SupervisingManager] as [Employees].[Managerial].currentmember.member_name
returns that currentmember. I also experimented with
measures.[SupervisingManager] as [Employees].[Managerial].currentmember.parent.member_name
but the issue with this is that the currentmember can be located at any within the hierarchy. The only way I can think of doing this is to do a massive case statement, get the ordinal value of the current member and use the appropriate .parent.parent logic. Is there a neater way to do this?
Maybe something along these lines will help:
WITH
MEMBER measures.[FullTimeSalary] AS
measures.[Salary] * measures.[FullTimeFactor]
MEMBER measures.[SupervisingManager] AS
IIF
(
[Employees].CurrentMember.Parent.Level.Name = 'Level 03'
,[Employees].CurrentMember.Parent.Member_Caption
,'n/a'
)
SELECT
{
measures.[FullTimeSalary]
,measures.[SupervisingManager]
} ON 0
,NON EMPTY
{[Employess].[All Employees].[All].Children} ON 1
FROM MyCube
WHERE
[Time].[Month].&[201501];
I have a table which looks like the following:
date code name score set
09/09/12 967873 Team A 24 1
09/09/12 967873 Team B 22 1
09/09/12 967873 Team A 21 2
09/09/12 967873 Team B 16 2
02/04/12 965454 Team X 21 1
02/04/12 965454 Team Y 19 1
02/04/12 965454 Team X 21 2
02/04/12 965454 Team Y 19 2
you guessed it right! it's a volleyball match! however, I would like my output to be in a single line (I already have retrieved the above table from database). For example:
date code Teams Set-1 Set-2 Set-3
09/09/12 967873 Team A VS.Team B 24-22 21-16 -
and so on....
I would like to use vb.net dataReader and html tables/dataset to put the above table in the right format for the user, but having trouble with the algorithm.
**Notice that the game could have a third set as well
Thanks,
... This could be overkill, but I would do this by just creating a custom object where you can parse out the data the way you need it.
For example:
Public Class VolleyBallData
Public Property dbDate As String
Public Property dbCode As String
Private _Teams(2) As String
Public WriteOnly Property dbTeams As String
Set(ByVal value As String)
_Teams = Value.Split({" VS."}, StringSplitOptions.None)
End Set
End Property
Private _Set1(2) As String
Public WriteOnly Property dbSet1 As String
Set(ByVal value As String)
_Set1 = Value.Split({"-"}, StringSplitOptions.None)
End Set
End Property
...
Then, you could just create an output function from your custom object that outputs the data in exactly the way you need it into, say, a List(of DataRow), given that you know that each first element in each array is Team 1's data and each second element is Team 2's.
Then just add those rows to your parent datatable.
Or, quite honestly, you could just as easily do this via functions... I just like custom objects for data validation purposes.
Hope this makes sense...