How do I properly design a Z schema for this scenario? - formal-methods

All of the examples I found had only 2 declarations such as name and date OR members and telephone. However, my scenario is this :
I would like to create a Z schema called AppointmentDB. AppointmentDB
keeps appointments details such purpose, attendees and schedule
My take (EDITED):
There are 5 declarations and 1 predicate
|--AppointmentDB----------------
|attendees : P Person
|appointments : P APPOINTMENT
|hasAppointment : Person ↔ APPOINTMENT
|schedule : APPOINTMENT → DateTime
|purpose : APPOINTMENT → Report
|-----------------------------
|attendees ⊆ dom(hasAppointment)
|-----------------------------
As you can see, I'm trying to link the APPOINTMENT to all its other attributes. Is my schema correct or complete or how can I optimize it further? Also, how do I know which relation should I consider from the relation to define inside the predicate part?

In your specification there is e.g. no link between the purpose and schedule. You define schedule in a way that a person is mapped to an arbitrary number of times and purpose maps a person to an arbitrary number of words. But there is no way to tell at which time the person has an appointment with what purpose.
I suppose you want to have a single appointment have a time and a purpose. My suggestion (there are actual many ways to achieve this) is to introduce a data type for appointments, e.g. with a carrier set:
[APPOINTMENT]
Then you can specify that a person has an arbitrary number of appointments:
|--------------------
| appointments: P APPOINTMENT
| hasAppointment: Person <-> APPOINTMENT
|----
| appointments = ran(hasAppointment)
|--------------------
And for each appointment you can specify its time and purpose:
|--------------------
| schedule: appointments --> DateTime
| purpose: appointments --> Word
|--------------------
So this is by not everything you specified in your schema but I'm not sure how exactly to interpret e.g. object or availability of your specification. But I think the basic approach to make the appointment itself an object will be helpful in most scenarios.
Another approach instead of introducing a type APPOINTMENT would be to define a schema Appointment and use it like a record data type.

Related

How to get employee transport and accommodation allowance?

I am working on one of our HR system which have integration with SAP, I am using SAP Connector for Microsoft .NET 3.0 and it's working fine for getting basic employee data using BAPI_EMPLOYEE_GETDATA function module.
I wants to know is there any function module in SAP to get employee transport and accommodation allowances.
As far as I know there is no single allowance value for employee in SAP HR. They can be set per diem, per expense type, per country destination, etc.
The most simple and obviuos setting that came to my mind is Define Maximum Rates and Default Values for Expense Types, which is stored in V_T706B2 customizing view
Here you can configure defaults, errors and warnings for expense receipts. Here is the excerpt from help:
In this IMG activity, you define maximum rates depending on the trip provision variant and trip expense type for individual receipts. For the differentiation of maximum rates within a trip expense type, the following parameters are available:
•Statutory and enterprise-specific trip types
•Trip activity type
•Trip country and trip region
•Statutory and enterprise-specific reimbursement group for meals and accommodations
Key piece here is individual receipts, you gotta understand that travel expenses in SAP are settled per trip per destination per receipt. So it may be dozens of receipts in the single trip.
The botton line: the total allowance value per employee (per day/month/year) that you want, may not be available out of the box in SAP ERP and is coded/customized by each client. I saw multiple ways to implement it, but none of them are standard so I will not give them here. In case you are not sure which allowance type do you need, it's better to ask your customer directly about it.
The snippet how to fetch the above Maximum Rates and Default Values for Expense Types is based on standard module RFC_READ_TABLE for querying SAP tabular data.
Here we fetch T706B2 table but I want to highlight it is not equivalent to V_T706B2 view, ideally you must create a database view wrapper for V_T706B2 view and fetch it, however this may not be feasible on your system due to security policy.
The query is context-dependent and here you must know many parameters like travel provision plan MOREI, expense type SPKZL and maybe others. They should be provided by your business analyst, I give this snippet only as a reference (!), it may not be suited for your particular case.
DATA: obj_data TYPE REF TO data,
lt_options TYPE TABLE OF rfc_db_opt,
ls_option TYPE rfc_db_opt,
lt_fields TYPE TABLE OF rfc_db_fld,
ls_field TYPE rfc_db_fld,
lt_entries TYPE STANDARD TABLE OF tab512.
FIELD-SYMBOLS: <fs_tab> TYPE STANDARD TABLE.
TRY.
ls_option-text = ` MOREI = '01' AND SPKZL = 'ABZA' AND BEGDA >= '20220101' AND ENDDA <= '20221231' `.
APPEND ls_option TO lt_options.
ls_field-fieldname = 'MOREI'.
APPEND ls_field TO lt_fields.
ls_field-fieldname = 'SPKZL'.
APPEND ls_field TO lt_fields.
CALL FUNCTION 'RFC_READ_TABLE'
EXPORTING
query_table = 'T706B2'
TABLES
options = lt_options
fields = lt_fields
data = lt_entries.
CATCH CX_SY_DYNAMIC_OSQL_SYNTAX INTO DATA(oref).
DATA(text) = oref->get_text( ).
MESSAGE text TYPE 'E'.
ENDTRY.
It is an ABAP snippet, to wrap it for SAP .Net Connector check this answer.

What is most efficient way to find ‘inverse' of getting all records that match particular criteria

I am trying to find the most efficient way to find ‘inverse' of getting all records that match particular criteria
I.e. find all predefined criteria from a set that a particular record matches
I have a table of 'target' criteria that has many records - each built using a querybuilder javascript component - so each target record has its criteria stored as a json string in a field.
I also have a standard 'person' table
It is straight forward to query how many people fit a particular target.
What I am trying to do is get all targets that match a particular person
Is there a more efficient way than just running each target's criteria against a person?
Open to suggestions beyond just sql - e.g. caching , hashing or building up some kind of lookup table/file
Edit:
Hopefully tables below clarify this issue. If I parsed and ran the 'Good Eyesight' target criteria I would expect to return both Bob and Sue
But I want to know that Bob matches the 'Young People' and 'Good Eyesight' target. I will have thousands of users and probably up to 50 active targets.
Table 1: Person
ID Name Age Fav_Vegetable
---------------------------------
1 Bob 20 Carrot
2 Sue 40 Carrot
Table 2: Target
ID Name Criteria_JSON
---------------------------------
1 Young People {"rule": "young_age", "selectedOperator": "<","selectedOperand": "Age","value": "30"}
2 Old People {"rule": "old_age", "selectedOperator": ">","selectedOperand": "Age","value": "30"}
3 Good Eyesight {"rule": "vegetable","selectedOperator": "equals","selectedOperand": "Fav_Vegetable","value": "Carrot"}
The answer I have come up with is to run all targets against all people and maintain an index type table of the results.
i.e. have a table TargetIndex with columns targetId, personId
Then when I need to know the targets for a particular person I can just check against the TargetIndex table rather than rerunning queries.
Obviously these results would need to be refreshed as the target or people records change - - probably whenever a target is added/edited and refreshed periodically (hourly/nightly?) to pick up changes in people
Thanks for people's thoughts

Data Type Qualifiers Definition PostgreSQL

How would I go about defining a table with a language specific (qualified) attribute?
For example:
ID| object |description (english)|description (french)| size | color (english) | color (french)
in the above example we have 3 'normal' fields and 2 language qualified fields : description and color.
What is best practice for defining these type of fields within one table?
There are different ways of doing this. But a method for your specific data is to have another table with one row per language. Such as table would have:
objectLanguageId (serial column to identify the row)
objectId (reference to a table with one row per object)
language
description
color
Then the "object" table would have
objectId
objectName
size
Note: This is definitely not the only approach. If you need everything in your system translated, then you want a more sophisticated and generic mechanism. You may also need to take into account things like French sizes are different from sizes in other countries -- even countries that speak the same language.

Database design solution

I am having the following case:
There is entity 'Master_Entity'. This entity has properties as name, type, duration etc. There are other two type of entities 'Entity' and 'Sub-Entity'. There are identical as the 'Master_Entity' (They have absolutely the same properties).
At the end the 'Master_Entity' should hold a collection of 'Entity' and 'Entity' should hold a collection of 'Sub-Entity'. The tricky part is that records of type 'Entity' can be part of different 'Master_Entity' (same for 'Sub-Entity'), but they can have different values for duration for example. How can achieve such modularity?
Here I came up with, but it's not quite do the work. May you guys help me with this.
Edit: Imagine this as some sort of a work tracker. For example you have a 'Create PHP App' (Master entity). This entity contains duration of how long it will take to finish this job. In addition it contains a entity 'Writing Code' (Entity) and this one can be divided to 'Writing Http Client' (Sub-Entity) which has duration property which is specific for this job.
On other side you might have other job: 'Create an Java App' (Master Entity) which will contain the same 'Writing Code' entity, but with duration which will have different value, because of the context of the Application you are building.
I want to have a single record 'Writing Code', but the duration value that it have should be different for every job it's assigned to. How can achieve that with creating a minimum duplicating records of type 'Entity'?
It sounds like something like these 3 tables will work for you:
Entity
* Id
* Name
* Type
EntityGroup
* Id
* Name
* ParentEntityGroupId
* ParentEntityId
EntityRelationship
* Id
* EntityId
* ParentEntityId
* EntityGroupId
With this structure, you can have an Entity be a member of a Group, or a solo Child of another Entity. You can also have a Group be a Child of an Entity, or even a Child of another Group. Without knowing specifics of your data, it's hard to know what you might need, but this should get you started.
From what you have said, it seems that you don't need EAV at all because you don't have different properties for each item just different values. And thus you should not be using it.
What you need is a combination of lookup tables and then tables that address the actual tracking history of the work. This is because this is time sensitive data. The tasks at the time the projects was created may be substantially different than the tasks associated with that task group two years from now, but you need to record the tasks at the the time of creation). Note that this is not denormalizing, it is creating a picture of data in time. The real duration always goes to teh project not ever to the Task. In the task, you can have a suggested duration to use as a starting point. I used a similar design (with far more fields of course) to design a database for building sales proposals for technical-hardware related projects. The real key here is to recognize what data needs to be stored as a point time time and what is lookup data used to build the final project data. If someone adds a new task to the "Create a Java App" group, you don't want to change details about projects already completed or in work, only new projects.
So you need:
Task group
Task Group ID
Task Group Name
Task
TaskID
Task Name
SuggestedDuration (can be null if you have tasks that are always different
but filled in for tasks that usually have a similar duration)
Task_Taskgroup
TaskID
TaskGroupID
Project
ProjectID
ProjectName
TaskGroupID
ProjectTask (should be filled in automatically when the task group is
chosen for the project)
ProjectID
Task ID
EstimatedDuration (fills in the default value, but can be changed
by the person creating the work project)
ActualDuration (Field in after the task is done, can be used by an
analyst to create more reflective task default duration values)
Of course each of these tables may have other fields depending on the need.

Which is the best design for categorizing items?

I have four levels for categorizing items according to their attributes. Some items may not require all subcategory levels and some items may share the same subcategory values.
Examples:
Category1 Category2 Category3 Category4
--------- --------- --------- ---------
Jewelry Ring Wedding
Jewelry Bracelet Serpentine
Jewelry Necklace Serpentine
Equipment Tool Power Drill
Equipment Tool Hand Jigsaw
Accessory Battery AA
Accessory Movie DVD Action
Accessory Game PS3 Combat
I want the lookup tables to contain values which are related to each item so that when users select a value from the dropdown list in the first category, the corresponding values in the next subcategory will automatically drop down (cascade), and so on.
I will predefine non-deletable, non-updatable values for most common items, however I cannot provide all possible items, for which I want to allow users to add values from the second level on down.
The objective for classifying each item is to provide a uniform method for describing items and for queries to effectively return all desired items.
Questions:
How can I make sure that new values which are added by users will link properly to parent or child values?
Should I allow users to add new categories and subcategories or should I force them to only select from pre-defined values, chose 'Other' value if their item does not fit into one of the pre-defined and enter a free-form comment?
Is the current method I have defined the best way or do you have a better suggestion?
Below are the current tables and relationships I have defined:
Columns MS-Access Informix Comments
-------------- ------------ -------- ----------------------------------------
Primary keys Autonumber SERIAL
Foreign keys Long Integer INTEGER
English Text VARCHAR Description in English language.
Spanish Text VARCHAR Description in Spanish language.
NonDelete Yes/No CHAR(1) Cant delete predefined value if TRUE.
NonUpdate Yes/No CHAR(1) Cant update predefined value if TRUE.
Deleted Yes/No CHAR(1) User-defined value cant be used anymore.
StockKeptUnit Yes/No CHAR(1) Non-serialized inventory item if TRUE.
Don't they properly link by definition? That is sort of the point of the PK/FK relationship, after all.
Presumably creation of a new tlkpItemCat2 involves selecting a valid parent tlkpItemCat1, or the INSERT would fail. As long as tlkpItemCat2.ItemCat1_SIID is defined as NOT NULL, you're pretty much assured of a valid relationship.
That doesn't guarantee that the end-user hasn't declared that a Necktie is a Power Tool, but that's a whole different problem.
Now, from experience with this exact issue (object categorisation), I can tell you that although this design looks quite elegant and useful, it is awful from a usability perspective. Your user has to know the hierarchy in advance to quickly locate the correct category for an item. And once end-users start adding levels to your hierarchy, it becomes a nightmare of back-and-forth, dead-end searches trying to locate the correct combination of Cat1/Cat2/Cat3 to apply - which leads to anything-will-do-just-to-get-past-this-screen categorisation.
A better approach is to allow the user to simply type in 'Jigsaw', and return a list along the lines:
Did you mean:
[] Equipment | Tool | Power | Jigsaw
[] Equipment | Tool | Hand | Jigsaw
[] Game | Childrens | Jigsaw
[] Accessory | DVD-Movie | Horror | Jigsaw
[] ... or [something else]?
Yes, it's more work, but from a UI and UX perspective, worthwhile.
This should allow for infinite categories. You'll need to enforce non-orphaning through your UI or OnChange events.
Then your table content would look like this: