I've got a structure of authors, readers, and preferences (high, medium, low, or blacklisted). All preferences are medium unless a rule overrides it. Whenever a new book becomes available, one reader should be given the opportunity to read that book. Some readers like particular authors, so the rule for that would look like:
author
reader
preference
Charles Dickens
Joe Bloggs
high
Some authors might be blacklisted for all readers (null):
author
reader
preference
Adolf Hitler
null
blacklisted
But a reader can override that rule:
author
reader
preference
Adolf Hitler
Mary Jones
medium
Some readers mightn't have as much time to read and want to read fewer books by any author (null):
author
reader
preference
null
John Smith
low
But that reader might make time for a particular author:
author
reader
preference
Geoffrey Chaucer
John Smith
high
So, all those rules in combination look like:
author
reader
preference
Charles Dickens
Joe Bloggs
high
Adolf Hitler
null
blacklisted
Adolf Hitler
Mary Jones
medium
null
John Smith
low
Geoffrey Chaucer
John Smith
high
When a new book by Charles Dickens becomes available, Joe Bloggs is more likely to be given the opportunity to read it, and John Smith is less likely, with Mary Jones having an average chance.
When a new book by Geoffrey Chaucer becomes available, Joe Bloggs and Mary Jones both have an average chance to be given the opportunity to read it, and John Smith is more likely.
If a new book by Adolf Hitler becomes available, Joe Bloggs will not be given an opportunity to read it, Mary Jones will have an average chance, and the rules for John Smith are inconsistent (Adolf Hitler blacklisted for any reader and any author low preference) and need to be resolved.
When the rules are being edited, I need a way to validate all the rules against each other. For instance, Joe Bloggs can't say that his preference for Charles Dickens is both high and low. If that happened, I want both rules to be highlighted. And in the above example, the two rules "Adolf Hitler, null, blacklisted" and "null, John Smith, low" should both be highlighted until resolved, for example with another row "Adolf Hitler, John Smith, blacklisted".
However, in AngularJS, I only know how to validate single inputs, not how to treat the entire row as a single input and also to make sure it doesn't clash with any other rows.
e.g.
<textarea ng-model="description" ng-minlength="5" ng-maxlength="255" required="required"></textarea>
How can I validate a compound item i.e. {rules: [{author: 1, reader: 2, preference: "high"}]} against all other items?
<div ng-repeat="rule in rules">
<input ng-model="rule.author">
<input ng-model="rule.reader">
<input ng-model="rule.preference">
</div>
I.e. I want to validate rule as an entire object, not just rule.author, rule.reader, and rule.preference.
Related
I am new to coding. Now I have a employee table looked like below:
Name
Hometown
School
Jeff
Illinois
Loyola University Chicago
Alice
California
New York University
William
Michigan
University of Illinois at Chicago
Fiona
California
Loyola University Chicago
Charles
Michigan
New York University
Linda
Indiana
Loyola University Chicago
I am trying to get those employees in pairs where two employees come from different state and different university. Each person can only be in one pair. The expected table should look like
employee1
employee2
Jeff
Alice
William
Fiona
Charles
Linda
The real table is over 3,000 rows. I am trying to do it with SQL or Python, but I don't know where to start.
A straightforward approach is to pick employees one by one and search the table after the one for an appropriate peer; found peers are flagged in order to not be paired repeatedly. Since in your case a peer should be found after a few steps, this iteration will likely be faster than operations which construct whole data sets at once.
from io import StringIO
import pandas as pd
# read example employee table
df = pd.read_table(StringIO("""Name Hometown School
Jeff Illinois Loyola University Chicago
Alice California New York University
William Michigan University of Illinois at Chicago
Fiona California Loyola University Chicago
Charles Michigan New York University
Linda Indiana Loyola University Chicago
"""))
# create expected table; its length is half that of the above
ef = pd.DataFrame(index=pd.RangeIndex(len(df)/2), columns=['employee1', 'employee2'])
k = 0 # number of found pairs, index into expected table
# array of flags for already paired employees
paired = pd.Series(False, pd.RangeIndex(len(df)))
# go through the employee table and collect pairs
for i in range(len(df)):
if paired[i]: continue
for j in range(i+1, len(df)):
if not paired[j] \
and df.iloc[j]['Hometown'] != df.iloc[i]['Hometown'] \
and df.iloc[j]['School'] != df.iloc[i]['School']:
# we found a pair - store it, mark employee j paired
ef.iloc[k] = df.iloc[[i, j]]['Name']
k += 1
paired[j] = True
break
else:
print("no peer for", df.iloc[i]['Name'])
print(ef)
output:
employee1 employee2
0 Jeff Alice
1 William Fiona
2 Charles Linda
So I've been developing a sort of data entry platform within accessing using forms and subforms.
I have a form titled PHYSICIAN. Each physician will have basic data like first/last name, DOB, title, contract dates, etc. The aspect I'm wanting to cover is addresses as they may have multiple, since they may work/practice at 2 or 3 or even 10 different locations.
Instead of having our data entry team key in a full record each time they need to add an address, I'd like a way for the form to retain ALL information not related to the address.
So if Ken Bone works at 7 places, I want to allow them to key all of those addresses a bit more efficiently than creating a new record.
There's one main issue I'm running into --- A subform or autopopulate option doesn't necessarily increment the autonumber ID (primary key) for the record. All of the information is being stored in 1 master table.
Is there a way around this or a more logical approach that you folks might suggest?
I recommend that you have a couple of tables perhaps even three.
tblDoctorInfo
- Dr_ID
- Name
- DOB
- Title
tblAddresses
- AddressID
- Address1
- Address2
- City
- State
- Zip
- Country
tblDr_Sites
- DrSites_ID
- Dr_ID
- AddressID
The tables might have data like this.
tblDoctorInfo
1, Bob Smith, 12/3/1989, Owner
2, Carl Jones, 1/2/1977, CEO
3, Carla Smith, 5/3/1980, ER Surgeon
tblAddresses
1, 123 Elm St, Fridley, MN 55038
2, 234 7th St, Brookdale, MN 55412
3, 345 Parl Ave, Clinton, MN 55132
tblDr_Sites
Then you could associate the tables with the third table. (Note each of the three tables have an ID field that increments).
1,1,1 This record means Dr. Bob works in Fridley
2,1,2 This record means Dr. Bob works in Brookdale
3,3,1 This record means Dr. Carla works in Fridley
4,2,3 This record means Dr. Carl works in Clinton
5,2,2 This record means Dr. Carl works in Brookdale
6,2,1 This record means Dr. Carl works in Fridley
(revised) I have a web app where information will be entered for a user. First and last name as well as 3 Affiliations (primary, secondary, and tertiary) associated with the person. Each affiliation has 3 components (title, department, and university). So for example one record could be for:
User: Bob, Robertson
Affiliation1: Professor, Chemistry, U. Florida
Affiliation2: Director, Amazing Chemistry Institute, U. Florida
Affiliation3: Affiliated Faculty, BioChemistry, Florida Tech.
Also, Title and Department are text input fields but Univ. refers to a specific list of about 3000 university names 'univ_name' which is why it has it's own table. also affiliationOrdinal would be something like (1st, 2nd, 3rd)
Users Affiliation Univ.
======= ============ =========
id_user id_affiliation id_univ
FirstName id_user univ_name
LastName affiliationOrdinal
title
department
id_univ
Thanks Sean for your feedback, I started thinking of this more as a user with multiple addresess type of problem and that has been solved many times over it seems. I picked this one as a reference. Mysql database design for customer multiple addresses and default address. So the above should be a bit closer to workable right?
Does someone know how I can put more than one value in one field to make a relation between two different records?
Google translation (from German):
Using multivalued fields
In most systems, DBMS (database management systems), including earlier
versions of Microsoft Access, you can only store a single value in a
field. In Microsoft Office Access 2007, you can also create fields
that contain multiple values, such as a list of categories to which
you have assigned a condition. Multivalued fields are used in specific
situations, such as when you use Office Access 2007 to work saved in a
Windows SharePoint Services 3.0 list that contains a field of one of
the field types with multiple values that are available in Windows
data SharePoint Services.
This topic describes how to create and use multivalued fields in
Office Access 2007 and Windows SharePoint Services, how to create
multivalued fields and used, and how to use multivalued fields in a
query.
You can use multi-value Lookup fields in JOIN conditions (via their .Value property), but be aware that if there is such a field on both sides of the join then it will produce a match when any item matches on the joined fields, not when all items match. This may or may not be desirable, depending on the situation.
Case 1: Students with allergies
A school administrator needs to keep track of students with allergies and provide them with a list of meals that they should avoid when eating at the school cafeteria.
[Students]
ID Student Allergies
-- ------- ---------
1 Alice Eggs, Soy
2 Bradley Peanuts
3 Carol
4 Dennis Soy
[Meals]
ID Meal Allergens
-- ------------- ---------
1 Thai stir-fry Peanuts
2 Tofu omlette Eggs, Soy
3 Waffles Eggs
The query
SELECT Students.Student, Students.Allergies, Meals.Meal, Meals.Allergens
FROM Students INNER JOIN Meals ON Students.Allergies.Value = Meals.Allergens.Value;
returns
Student Allergies Meal Allergens
------- --------- ------------- ---------
Alice Eggs, Soy Tofu omlette Eggs, Soy
Alice Eggs, Soy Waffles Eggs
Bradley Peanuts Thai stir-fry Peanuts
Dennis Soy Tofu omlette Eggs, Soy
This is appropriate, since Alice should avoid meals that contain any ingredients to which she is allergic.
Case 2: Hotel requirements
[Travellers]
ID Traveller Requirements
-- --------- -------------------------
1 Gord free WiFi, in-room coffee
[Hotels]
ID Hotel Amenities
-- ------------ ----------------------------
1 Budget Motel free WiFi, in-room coffee
2 Fancy Hotel in-room coffee, room service
The query
SELECT Travellers.Traveller, Travellers.Requirements, Hotels.Hotel, Hotels.Amenities
FROM Hotels INNER JOIN Travellers ON Hotels.Amenities.Value = Travellers.Requirements.Value;
returns
Traveller Requirements Hotel Amenities
--------- ------------------------- ------------ ----------------------------
Gord free WiFi, in-room coffee Budget Motel free WiFi, in-room coffee
Gord free WiFi, in-room coffee Fancy Hotel in-room coffee, room service
The query returns both properties because they both offer in-room coffee. However, Fancy Hotel does not offer free WiFi, so I would prefer not to stay there. In this case the default join behaviour is not desirable (to me).
I am working on a requirement to match people from different databases. One tricky problem is variance in names like Bob - Robert, Jim - James, Lizzy - Elizabeth etc across databases.
Is there a lookup/translation available for this kind of a requirement.
Take a look at my answer (as well as the others) here:
Tools for matching name/address data
You'd need to implement a lookup table with the alternate names in it:
Base | Alternate
----------------
Robert | Bob
Elizabeth | Liz
Elizabeth | Lizzy
Elizabeth | Beth
Then search the database for the base name and all alternates. You'll end up with a number of multiple matches which will then need to be checked to see if they really match based on a comparison of whatever other data you have in the two databases. Maybe the dates of the records in each database could be used - records entered close in time indicate the same person.