What's the UML syntax for multiplicity? ( inside the class box ) - oop

I know it is possible to specify the multiplicity within the same class box, without having to draw the link to another class.
My question is, Where should the multiplicity go, after the name or after the type?
Is it:
visibility name multiplicity : type
as
+ clients [0..n] : Client
or
visibility name : type multiplicity
as
+ clients : Client [0..n]
I have two books (Applitying UML and Patterns by Larman and UML and the Unified process by Arlow and Newstadt ) but they differ

Pulled from printed page 107 of the UML 2.2 Superstructure OMG Specificiation
Example ...
+createWindow (location: Coordinates, container: Container [0..1]): Window
MORE Examples from the multiplicity element spec, on printed page 97.
Example from Spec on multiplicity.
|--------------------------------------------|
| Customer |
|--------------------------------------------|
| purchase : Purchase [*] {ordered, unique} |
| account: Account [0..5] {unique} |
| |
|--------------------------------------------|

UML syntax is a diagrammatic syntax. See this multiplicity example from
http://www.ibm.com/developerworks/rational/library/content/RationalEdge/sep04/bell/
Figure 6: An example of a bi-directional association between a Flight class and a Plane class
----------------- -----------------
| Flight |0..* 0..1 | Plane |
| | ------------------| |
|---------------- -----------------

Related

How to make this very complicated query from three connected models with Django ORM?

Good day, everyone. Hope you're doing well. I'm a Django newbie, trying to learn the basics of RESTful development while helping in a small app project. We currently want some of our models to update accordingly based on the data we submit to them, by using the Django ORM and the fields that some of them share wih OneToMany relationsips. Currently, there's a really difficult query that I must do for one of my fields to update automatically given that filter. First, let me explain the models. This are not real, but a doppleganger that should work the same:
First we have a Report model that is a teacher's report of a student:
class Report(models.Model):
status = models.CharField(max_length=32, choices=Statuses.choices, default=Statuses.created,)
student = models.ForeignKey(Student, on_delete=models.CASCADE,)
headroom_teacher = models.ForeignKey(TeacherStaff, on_delete=models.CASCADE,)
# Various dates
results_date = models.DateTimeField(null=True, blank=True)
report_created = models.DateTimeField(null=True, blank=True)
.
#Other fields that don't matter
Here we have two related models, which are student and headroom_teacher. It's not necessary to show their models, but their relationship with the next two models is really important. We also have an Exams model:
class Exams(models.Model):
student = models.ForeignKey(student, on_delete=models.CASCADE,)
headroom_teacher = models.ForeignKey(TeacherStaff, on_delete=models.CASCADE,)
# Various dates
results_date = models.DateTimeField(null=True, blank=True)
initial_exam_date = models.DateTimeField(null=True, blank=True)
.
#Other fields that don't matter
As you can see, the purpose of this app is akin to reporting on the performance of students after completing some exams, and every Report is made by a teacher for specific student on how he did on those exams. Finally we have a final model called StudentMood that aims to show how should an student be feeling depending on the status of their exams:
class StudentMood(models.Model):
report = models.ForeignKey(Report, on_delete=models.CASCADE,)
student_status = models.CharField(
max_length=32, choices=Status.choices,
default=None, null=True, blank=False)
headroom_teacher = models.ForeignKey(TeacherStaff, on_delete=models.CASCADE,)
And with these three models is that we arrive to the crux of the issue. One of our possible student_status options is called Anxious for results, which we believe a student will feel during the time when he already has done an exam and is waiting for the results.
I want to automatically set my student_status to that, using a custom manager that takes into account the date that the report has been done or the day the data has been entered. I believe this can be done by making a query taking into account initial_exam_date.
I already have my custom manager set up, and the only thing missing is this query. I have no choice but to do it with Django's ORM. However, I've come up with an approximate raw SQL query, that I'm not sure if it's ok:
SELECT student_mood.id AS student_mood_id FROM
school_student_mood LEFT JOIN
school_reports report
ON student_mood.report_id = report.id AND student_mood.headroom_teacher_id = report.headroom_teacher_id
JOIN school_exams exams
ON report.headroom_teacher_id = exams.headroom_teacher_id
AND report.student_id = exams.student_id
AND exams.results_date > date where the student_mood or report data is entered, I guess
And that's what I've come to ask for help. Could someone shed some light into how to transfer this into a single query?
Without having an environment setup or really knowing exactly what you want out of the data. This is a good start.
Generally speaking, the Django ORM is not great for these types of queries, and trying to use select_related or prefetches results in really complex and inefficient queries.
I've found the best way to achieve these types of queries in Django is to break each piece of your puzzle down into a query that returns a "list" of ids that you can then use in a subquery.
Then you keep working down until you have your final output
from django.db.models import Subquery
# Grab the students of any exams where the result_date is greater than a specific date.
student_exam_subquery = Exam.objects.filter(
results_date__gt=timezone.now()
).values_list('student__id', flat=True)
# Grab all the student moods related to reports that relate to our "exams" where the student is anxious
student_mood_subquery = StudentMood.objects.filter(
student_status='anxious',
reports__student__in=Subquery(student_exam_subquery)
).values_list('report__id', flat=True)
# Get the final list of students
Student.objects.values_list('id', flat=True).filter(
reports__id__in=Subquery(student_mood_subquery)
)
Now I doubt this will work out of the box, but it's really to give you an understanding of how you might go about solving this in a way that is readable to future devs and the most efficient (db wise).
So, the issue I was running into, is that the school has exam cycles each period, and it was difficult to retrieve only the students' report for this cycle. Let's assume we have the following database:
+-----------+-----------+----------------+-------------------+-------------------+------------------+
| Student | Report ID | StudentMood ID | Exam Cycle Status | Initial Exam Date | Report created a |
+-----------+-----------+----------------+-------------------+-------------------+------------------+
| Student 1 | 1 | 1 | Done | 01/01/2020 | 02/01/2020 |
| Student 2 | 2 | 2 | Done | 01/01/2020 | 02/01/2020 |
| Student 1 | 3 | 3 | On Going | 02/06/2020 | 01/01/2020 |
| Student 2 | 4 | 4 | On Going | 02/06/2020 | 01/01/2020 |
+-----------+-----------+----------------+-------------------+-------------------+------------------+
And Obviously, I wanted to limit my query to just this cycle, like this:
+-----------+-----------+----------------+-------------------+-------------------+------------------+
| Student | Report ID | StudentMood ID | Exam Cycle Status | Initial Exam Date | Report created a |
+-----------+-----------+----------------+-------------------+-------------------+------------------+
| Student 1 | 3 | 3 | On Going | 02/06/2020 | 01/01/2020 |
| Student 2 | 4 | 4 | On Going | 02/06/2020 | 01/01/2020 |
+-----------+-----------+----------------+-------------------+-------------------+------------------+
Now, your answer, trent, was really useful, but I'm still having issues retrieving in the shape of the above:
qs_exams = Exams.objects.filter(initial_exam_date__gt=now()).values_list('student__id', flat=True)
qs_report = Report.objects.filter(student__id__in=qs_exams).values_list('id', flat=True)
qs_mood = StudentMood.objects.select_related('report') \
.filter(report__id__in=qs_report).order_by('report__student_id', '-created').distinct()
But this query is still giving me all the StudentMoods throughout the school year. Sooooo, any ideas?

What does the DIMENSION TYPE do in SSAS?

I am more experienced with SSAS Tabular, but in my role at work I must support SSAS Multidimensional cubes. Earlier today I tried to add a time intelligence calculation (Parallel Period) to SSASMD connection in Excel pivot table. But the evaluation error-ed out regardless of the syntax I used.
After struggling with the error I came across this article at SQL Server Central (Stairway to MDX - Level 13: MDX Time/Date Series Functions: LastPeriods() and ParallelPeriod() Functions).
My question: Does the DATE dimension have to have Type 'TIME' in order for date functions to work? Here is the syntax for my YOY calculation.
Lbs Sold YOY Actuals-v1
(
[DATES].[INVOICE_DATE].[INVOICE_DATE].CurrentMember.PrevMember
,[Measures].[Lbs Sold]
)
Lbs Sold YOY Actuals-v2
(ParallelPeriod(
[INVOICE_DATE].[DATES].CurrentMember.Level,
1,
[INVOICE_DATE].[DATES].CurrentMember
),
[Measures].[Lbs Sold])
I am more experienced with DAX than MDX, so any insights would be appreciated.
My MDX calculation sources...
How to create a period over period Measurement in MDX?
https://xzwang.wordpress.com/2013/08/13/a-better-way-to-write-mdx-period-over-period-calculations/
http://pragmaticworks.com/ResourcesDup/Cheat-Sheets/MDX-Expression-Cheat-Sheet
Dimension Types
Also I am curious, what are all of the other Dimension Types used for? Does changing that from 'Normal' to any of the others give the cube extra functionality? I found some descriptions online (pasted below), but I am curious what this actually does?
From the Microsoft Docs...
The Type property setting provides information about the contents of a
dimension to server and client applications. In some cases, the Type
setting only provides guidance for client applications and is
optional. In other cases, such as Accounts or Time dimensions, the
Type property settings for the dimension and its attributes determine
specific server-based behaviors and may be required to implement
certain behaviors in the cube. For example, the Type property of a
dimension can be set to Accounts to indicate to client applications
that the standard dimension contains account attributes.
+-----------------+---------------------------------------------------------------------------+
| Type | Description |
+-----------------+---------------------------------------------------------------------------+
| Regular | Default for dimensions that are not set to a specified type |
+-----------------+---------------------------------------------------------------------------+
| Time | Used for dimensions whose attributes represent time periods |
+-----------------+---------------------------------------------------------------------------+
| Geography | Used for dimensions whose attributes represent geographical inform-ation |
+-----------------+---------------------------------------------------------------------------+
| Organization | Used for dimensions whose attributes represent organizational information |
+-----------------+---------------------------------------------------------------------------+
| BillOfMaterials | Used for dimensions whose attributes represent inventory and |
| | man-ufacturing information |
+-----------------+---------------------------------------------------------------------------+
| Accounts | Used for dimensions whose attributes represent information used for |
| | financial reporting |
+-----------------+---------------------------------------------------------------------------+
| Customers | Used for dimensions whose attributes represent information about |
| | customers |
+-----------------+---------------------------------------------------------------------------+
| Products | Used for dimensions whose attributes represent information about products |
+-----------------+---------------------------------------------------------------------------+
| Scenario | Used for dimensions whose attributes represent information about plans |
| | and strategies |
+-----------------+---------------------------------------------------------------------------+
| Quantitative | Used for dimensions whose attributes represent quantitative inform-ation |
+-----------------+---------------------------------------------------------------------------+
| Utility | Used for dimensions whose attributes represent utility information |
+-----------------+---------------------------------------------------------------------------+
| Currency | Used for dimensions whose attributes represent currency inform-ation |
+-----------------+---------------------------------------------------------------------------+
| Rates | Used for dimensions whose attributes represent currency rate inform-ation |
+-----------------+---------------------------------------------------------------------------+
| Channel | Used for dimensions whose attributes represent channel information |
+-----------------+---------------------------------------------------------------------------+
| Promotion | Used for dimensions whose attributes represent marketing pro-motion |
| | information |
+-----------------+---------------------------------------------------------------------------+
You can give a try and experiment it by yourself. Let's pick the ParallelPeriod function:
select
ParallelPeriod(
[Customer].[Customer Geography].[Country],
3,
[Customer].[Customer Geography].[State-Province].[Hamburg]
) on 0
from [Adventure Works]
It returns South Australia. It makes no sense, but it works. So the answer to your question "Does the DATE dimension have to have Type 'TIME' in order for date functions to work?" is no.
In my experience, the only reason to change dimension type is when you are using semi-additive aggregation functions (i.e. LastNonEmpty) it requires a Time dimension within the cube in order to determinate the set of values per all intervals of the period.
Other than that, it's simply the client-side info. Clients can befit using different icons for different types and so on.

How to store two differents Graphs into one with Cypher?

For a later traitements with The project CAPS , I need to store 2 different Graphs into one:
Graph3=Graph1+Graph2
I tried to search for solutions to do that and I found UNION ALL but the last doesn't work as I expected. Is there another way to do that with Cypher?
Example :
val Graph1=session.cypher("""
| FROM GRAPH mergeGraph
| MATCH (from)-[via]->(to)
|WHERE substring(from.geohash,0,5)=substring(to.geohash,0,5)
| CONSTRUCT
| CREATE (h1:HashNode{geohash:substring(from.geohash,0,5)})-[COPY OF via]->(h1)
| RETURN GRAPH
""".stripMargin).graph
which contains this pattern :
val Graph2=session.cypher("""
| FROM GRAPH mergeGraph
| MATCH (from)-[via]->(to)
|WHERE substring(from.geohash,0,5)<>substring(to.geohash,0,5)
| CONSTRUCT
| CREATE (:HashNode{geohash:substring(from.geohash,0,5)})-[COPY OF via]->(:HashNode{geohash:substring(to.geohash,0,5)})
| RETURN GRAPH
""".stripMargin).graph
which contains this pattern :
With union All :
Graph3=Graph1.unionAll(Graph2)
I get this graph :
As you can see the green nodes are the nodes of Graph2 without relationship ! thats what i didn't expected.

SQL adjustable structure redundancy

I have to build a database structure which allow a totally modular structure. Let's take an example, it will be easier to understand.
We have a website record, looking like this :
WEBSITE A
| ----- SECTION A
| |-- SUBSECTION 1
| | | -- Data 1 : Value 1
| | | -- Data 2 : Value 2
| | | ...
| | | -- Data N : Value N
| |
| |-- SUBSECTION 2
| | | -- Data 52 : Value 1
| | | -- Data 53 : Value 2
| | | ...
| | | -- Data M : Value M
| |
| ...
|
| ----- SECTION B
| |
| ...
...
Model 1 :
And so on. The trouble is that I have to implement a permission system. For instance, User A have access to Section A,B,D,Z from website 1 whereas User 2 have acces to section C,V,W,X from website 2.
First, I though that building this as a tree would be the most efficient way to do.
Here is my first database representation :
TABLE website (id, id_client, name, address)
TABLE section (id, id_website, name)
TABLE sub_section (id, id_section, name)
TABLE data (id, id_sub_section, key, value)
With this representation, it would be easy to give some restricted access to the employees.
However, both websites will have common data. For instance, all websites will have section A,B,C,D with the same structure. It implies a lot of redundancy. For each website, we'll have a lot of common structure, the only difference will be the attribute value in the TABLE data.
The second problem is that this structure have to be totally modular. For instance, the admin should be able to add a section, a subsection or a data to a website record. That's the reason why I though that this model is easier to manage.
Model 2 :
I have a second model, easier to store but harder to exploit :
TABLE website (id, id_client, Value 1, Value 2, Value 3 ... Value N)
TABLE section (id, name, Data 1, Data 2, Data 3 .. Data N, ..., Data 52, Data 53, Data M) (it represents the name of the columns)
TABLE subsection (id, id_section, name, Data 1, Data 2, Data N)
By doing this, I have a table where data are stored and "structural tables" with section and subsection in common with both websites. If the admin wants to add a section / subsection, we're going back to the tree structure to store additionnal data, looking like this :
TABLE additional_section (id,id_website,name)
TABLE additionnal_subsection (id,id_section, id_additional_section, name)
TABLE additional_data (id, id_subsection, id_additionnal_subsection, key, value)
It avoids a lot of redundancy and facilitate the permissions management.
Here's my question :
What's the best model for this kind of application ? Model 1 ? Model 2 ? Another one ?
Thanks for reading and for your answers !
I would suggest that you modify Model 1.
You can eliminate the redundancy in the section table by removing the id_website FK from that table and create a new table between the website table and it.
This new table WebsiteSection has a PK that consist of an FK to website AND an FK to section, allowing each section to be part of multiple websites.
Section data that is common to all websites would then be stored in the section table while section data that is site specific would be stored in the WebsiteSection table.

OpenERP 6.0.4 - Stock Move Without picking_id

I'm having a weird problem in my Stock module.
once in a while when I check my stock move
I'll get a stock_move without picking_id in the database,
this is the example of the data:
id |create_date |write_date |product_id |location_dest_id |location_id |picking_id |State
------ -------------------- -------------------- ----------- ----------------- ------------ ------------ ------
144661|2013-08-03 15:55:00 |2013-08-03 16:23:57 |88754 | 9 |341 |40194 |draft
144662|2013-08-03 16:20:41 |2013-08-03 16:21:43 |88749 | 9 |970 | |draft
144663|2013-08-03 16:20:41 |2013-08-03 16:21:43 |76879 | 9 |970 | |draft
144664|2013-08-03 16:29:08 | |88749 | 9 |970 |40194 |draft
144665|2013-08-03 16:29:08 | |76879 | 9 |970 |40194 |draft
Have any of you ever met this issue before?
can you tell me how can I trace the cause of this issue?
thx for your help
In OpenERP, the stock.move objects that have values for picking_id are only the stock.move objects that correspond directly to the stock.picking object. For example, each line on a delivery order is a stock.move object with the picking_id field referencing the delivery order (stock.picking.out).
However, there are often other stock.moves that are generated by an action. For instance, when using the mrp module to manufacture a product, a stock.move is generated from the manufacturing location to the default inventory location. This stock.move does not correspond to a picking, and will not have a picking_id, but it may be chained to a stock.move that does belong to a stock.picking.
It is possible to trace chained stock.move objects to their eventual stock.picking object by looking at the field move_dest_id. This field represents the stock.move object that is next in the chain. Looking at your data, I would expect the two moves that are missing picking_ids to correspond to the two moves below with the same product_ids.