I am just beginning with Foundation 4 (coming from Bootstrap). There are a few concepts which I really cannot grasp, and there is no sign of explanation in their docs:
I have the following:
<div class="small-2 large-4 columns" style="background-color:lightgrey">. . .</div>
<div class="small-2 large-4 columns" style="background-color:lightgrey">. . .</div>
<div class="small-2 large-4 columns" style="background-color:lightgrey">. . .</div>
I really cannot understand what does small-2 and large-4 combined mean. In bootstrap there was just span* so I am guessing small-* is the same, but what about large-*? What does the large stand for? It also seems to me that I can omit one of the two, and have just large-* or small-*.
Also, what about the columns class? Why do I even need that if the "span" is already defined by the other classes?
Thanks in advance.
Using 'small' and 'large' you can define a column structure for small size screens and one for large size screens. So in your set up above when viewing in a large screen you would see four columns, and when in small you would see two columns.
e.g.
Large
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
-----------------------------------------------------------------------
| | | |
| div1 | div2 | div3 |
| | | |
-----------------------------------------------------------------------
Small
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
-----------------------------------
| | | |
| div1 | div2 | div3 |
| | | |
-----------------------------------
If you only use 'large-#' and omit a 'small-#' value, when viewing in on a small screen it defaults to 12 columns, essentially the same as writing small-12 large-4.
If you use only a 'small-#' and omit a 'large-#' value when viewing on all screen sizes it will use the 'small-#' value.
The 'column' class defines the div as a column. If you do not define and 'small-#' or 'large-#' it will set the div to 100% width (i.e. 12 columns).
Foundation also uses 'row'.
If you wrap a set of 'column' divs in a 'row' div all the 'column' divs will attempt to sit on the same row, if the total number of columns defined in a row is above 12 they will wrap. If the total number of columns is less than 12 then the columns will not wrap.
2 rows
<div class="row">
<div class="small-2 large-4 columns" style="background-color:lightgrey">...</div>
<div class="small-2 large-4 columns" style="background-color:lightgrey">...</div>
<div class="small-2 large-4 columns end" style="background-color:lightgrey">...</div>
</div>
<div class="row">
<div class="small-2 large-4 columns" style="background-color:lightgrey">...</div>
<div class="small-2 large-4 columns end" style="background-color:lightgrey">...</div>
</div>
Large
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
-----------------------------------------------------------------------
| | | |
| div1 | div2 | div3 | (row 1)
| | | |
-----------------------------------------------------------------------
-----------------------------------------------
| | |
| div1 | div2 | (row 2)
| | |
-----------------------------------------------
Small
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
-----------------------------------
| | | |
| div1 | div2 | div3 | (row 1)
| | | |
-----------------------------------
-----------------------
| | |
| div1 | div2 | (row 2)
| | |
-----------------------
now with 1 row
<div class="row">
<div class="small-2 large-4 columns" style="background-color:lightgrey">. . .</div>
<div class="small-2 large-4 columns" style="background-color:lightgrey">. . .</div>
<div class="small-2 large-4 columns" style="background-color:lightgrey">. . .</div>
<div class="small-2 large-4 columns" style="background-color:lightgrey">. . .</div>
<div class="small-2 large-4 columns end" style="background-color:lightgrey">. . .</div>
</div>
Large - 1-row columns greater than 12 so they wrap
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
-----------------------------------------------------------------------
| | | |
| div1 | div2 | div3 |
| | | |
-----------------------------------------------------------------------
| | |
| div4 | div5 |
| | |
-----------------------------------------------
Small - 1-row columns are less than 12, no wrapping
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
-----------------------------------------------------------
| | | | | |
| div1 | div2 | div3 | div4 | div5 |
| | | | | |
-----------------------------------------------------------
Hope this helps.
Note: When not using exactly 12 column as per the above layouts you need to add the class 'end' to the last column in the row to make it float left as the last column floats right by default.
e.g.
<div class="row">
<div class="small-2 large-4 columns" style="background-color:lightgrey">...</div>
<div class="small-2 large-4 columns" style="background-color:lightgrey">...</div>
</div>
Without the end class would look like this:
Large
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
----------------------- ------------------------
| | | |
| div1 | | div2 |
| | | |
----------------------- ------------------------
Small
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
----------- ------------
| | | |
| div1 | | div2 |
| | | |
----------- ------------
Related
I have these modules: Sales, Gender and Type in Django.
Table 1:
class Sales(models.Model):
sname = models.CharField(max_length=100, default="-")
sgender = models.ForeignKey(MainGender, on_delete=models.CASCADE)
stype = models.ForeignKey(MainTypes, on_delete=models.CASCADE)
sdate = models.TextField(default="-")
+------+-----+------+------+
| name |gende| type | date |
+------+-----+------+------+
| A | 1 | 1 | 2019 |
+------+-----+------+------+
| B | 2 | 1 | 2018 |
+------+-----+------+------+
| A | 1 | 3 | 2019 |
+------+-----+------+------+
| C | 2 | 3 | 2017 |
+------+-----+------+------+
| A | 1 | 2 | 2019 |
+------+-----+------+------+
Table 2 (key)
class MainGender(models.Model):
mid = models.CharField(max_length=25, default="-")
mgender = models.CharField(max_length=25, default="-")
+----+--------+
| id | gender |
+----+--------+
| 1 | Male |
+----+--------+
| 2 | Female |
+----+--------+
| 3 | - |
+----+--------+
Table 3 (key)
class MainTypes(models.Model):
tid = models.CharField(max_length=50, default="-")
ttype = models.CharField(max_length=50, default="-")
+----+------+
| id | type |
+----+------+
| 1 | U1 |
+----+------+
| 2 | X2 |
+----+------+
| 3 | B1 |
+----+------+
| 4 | H3 |
+----+------+
Then, I want to count all the things in the main table and show them in the template as below
+---------------+---+
| Total records | 5 |
+---------------+---+
| Male | 3 |
+---------------+---+
| Female | 2 |
+---------------+---+
| Type U1 | 2 |
+---------------+---+
| Type X2 | 1 |
+---------------+---+
| Type B1 | 2 |
+---------------+---+
| Type H3 | 0 |
+---------------+---+
I can only get total records in template by code below
in views.py
def Sale_p(request):
saless = Sale.objects.all()
return render(request, 'sale.html', {'sales':saless})
I tried these codes in the template (sale.html)
{{ sales|length }} (gives you total records in Table 1, in this example 5)
{{ sales.gender|length }} (gives nothing)
{{ sales.type|length }} (gives nothing)
{{ sales.gender_set|length }} (gives nothing)
{{ sales.type_set|length }} (gives nothing)
{{ sales.gender(1)|length }} (gives nothing)
{{ sales(gender='1')|length }} (gives nothing)
{{ sales.gender.count() }} (gives nothing)
They did not work in template. I want to see in records how many times we had 'male' or 'female' or types and so on...
in template, sale.html
+---------------+--------------------+
| Total records | {{ sales|length }} |
+---------------+--------------------+
| Male | ? |
+---------------+--------------------+
| Female | ? |
+---------------+--------------------+
| Type U1 | ? |
+---------------+--------------------+
| Type X2 | ? |
+---------------+--------------------+
| Type B1 | ? |
+---------------+--------------------+
| Type H3 | ? |
+---------------+--------------------+
What should be the codes to get the results for others?
Or should I use different ways in views.py?
Please refer to the link below:
https://docs.djangoproject.com/en/3.0/ref/templates/builtins/
I need to rank products for my dashboard. Each day, we store sales of products. In result we have this dataset example:
+-----------+------------+-------+
| product | date | sales |
+-----------+------------+-------+
| coffee | 11/03/2019 | 15 |
| coffee | 12/03/2019 | 10 |
| coffee | 13/03/2019 | 28 |
| coffee | 14/03/2019 | 1 |
| tea | 11/03/2019 | 5 |
| tea | 12/03/2019 | 2 |
| tea | 13/03/2019 | 6 |
| tea | 14/03/2019 | 7 |
| Chocolate | 11/03/2019 | 30 |
| Chocolate | 11/03/2019 | 4 |
| Chocolate | 11/03/2019 | 15 |
| Chocolate | 11/03/2019 | 10 |
+-----------+------------+-------+
My attempt
I actualy managed to Rank my products but not in the way I wanted it; In fact, the ranking process increase by the number of rows. for example, chocolate is first but we record 4 rows so coffee is ranked at 5 and not 2.
+-----------+------------+-------+-----+------+
| product | date | sales | sum | rank |
+-----------+------------+-------+-----+------+
| coffee | 11/03/2019 | 15 | 54 | 5 |
| coffee | 12/03/2019 | 10 | 54 | 5 |
| coffee | 13/03/2019 | 28 | 54 | 5 |
| coffee | 14/03/2019 | 1 | 54 | 5 |
| tea | 11/03/2019 | 5 | 20 | 9 |
| tea | 12/03/2019 | 2 | 20 | 9 |
| tea | 13/03/2019 | 6 | 20 | 9 |
| tea | 14/03/2019 | 7 | 20 | 9 |
| Chocolate | 11/03/2019 | 30 | 59 | 1 |
| Chocolate | 11/03/2019 | 4 | 59 | 1 |
| Chocolate | 11/03/2019 | 15 | 59 | 1 |
| Chocolate | 11/03/2019 | 10 | 59 | 1 |
+-----------+------------+-------+-----+------+
sum field formula formula:
sum =
SUMX(
FILTER(
Table1;
Table1[product] = EARLIER(Table1[product])
);
Table1[sales]
)
rank field formula :
rank = RANKX(
ALL(Table1);
Table1[sum]
)
As you can see, we get the following ranking:
1 : Chocolate
5 : Coffee
9 : Tea
Improvements
I would like to transform the previous result into :
1 : Chocolate
2 : Coffee
3 : Tea
Can you help me improving my ranking system and get a marvelous 1, 2, 3 instead of this ugly and not practical 1, 5, 9 ?
If you don't know the anwser, help by simply upvote the question ♥
Fortunately, this is an easy fix.
If you look at the documentation for the RANKX function, you'll notice an optional ties argument which you can set to Skip or Dense. The default is Skip but you want Dense. Try this:
rank =
RANKX(
ALL(Table1);
Table1[sum];
;;
"Dense"
)
(Those extra ; delimiters are there since we aren't specifying the optional value or order arguments.)
I have simplified my problem to solve. Lets suppose I have three tables. One containing data and specific codes that identify objects lets say Apples.
+-------------+------------+-----------+
| Data picked | Color code | Size code |
+-------------+------------+-----------+
| 1-8-2018 | 1 | 1 |
| 1-8-2018 | 1 | 3 |
| 1-8-2018 | 2 | 2 |
| 1-8-2018 | 2 | 3 |
| 1-8-2018 | 2 | 2 |
| 1-8-2018 | 3 | 3 |
| 1-8-2018 | 4 | 1 |
| 1-8-2018 | 4 | 1 |
| 1-8-2018 | 5 | 3 |
| 1-8-2018 | 6 | 1 |
| 1-8-2018 | 6 | 2 |
| 1-8-2018 | 6 | 2 |
+-------------+------------+-----------+
And i have two related helping tables to help understand the codes (their relationships are inactive in the model due to ambiguity with other tables in the real case).
+-----------+--------+
| Size code | Size |
+-----------+--------+
| 1 | Small |
| 2 | Medium |
| 3 | Large |
+-----------+--------+
and
+------------+----------------+-------+
| Color code | Color specific | Color |
+------------+----------------+-------+
| 1 | Light green | Green |
| 2 | Green | Green |
| 3 | Semi green | Green |
| 4 | Red | Red |
| 5 | Dark | Red |
| 6 | Pink | Red |
+------------+----------------+-------+
Lets say that I want to create an extra column in the original table to determine which apples are class A and class B given that medium green Apples are class A and large Red apples are class B, the other remain blank as the example below.
+-------------+------------+-----------+-------+
| Data picked | Color code | Size code | Class |
+-------------+------------+-----------+-------+
| 1-8-2018 | 1 | 1 | |
| 1-8-2018 | 1 | 3 | |
| 1-8-2018 | 2 | 2 | A |
| 1-8-2018 | 2 | 3 | |
| 1-8-2018 | 2 | 2 | A |
| 1-8-2018 | 3 | 3 | |
| 1-8-2018 | 4 | 1 | |
| 1-8-2018 | 4 | 1 | |
| 1-8-2018 | 5 | 3 | B |
| 1-8-2018 | 6 | 1 | |
| 1-8-2018 | 6 | 2 | |
| 1-8-2018 | 6 | 2 | |
+-------------+------------+-----------+-------+
What's the proper DAX to use given the relationships are initially inactive. Preferably solvable without creating any further additional columns in any table. I already tried codes like:
CALCULATE (
"A" ;
FILTER ( 'Size Table' ; 'Size Table'[Size] = "Medium");
FILTER ( 'Color Table' ; 'Color Table'[Color] = "Green")
)
And many variations on the same principle
Given that the relationships are inactive, I'd suggest using LOOKUPVALUE to match ID values on the other tables. You should be able to create a calculated column as follows:
Class =
VAR Size = LOOKUPVALUE('Size Table'[Size],
'Size Table'[Size code], 'Data Table'[Size code])
VAR Color = LOOKUPVALUE('Color Table'[Color],
'Color Table'[Color code], 'Data Table'[Color code])
RETURN SWITCH(TRUE(),
(Size = "Medium") && (Color = "Green"), "A",
(Size = "Large") && (Color = "Red"), "B", BLANK())
If your relationships are active, then you don't need the lookups:
Class = SWITCH(TRUE(),
(RELATED('Size Table'[Size]) = "Medium") &&
(RELATED('Color Table'[Color]) = "Green"),
"A",
(RELATED('Size Table'[Size]) = "Large") &&
(RELATED('Color Table'[Color]) = "Red"),
"B",
BLANK())
Or a bit more elegantly written (especially for more classes):
Class =
VAR SizeColor = RELATED('Size Table'[Size]) & " " & RELATED('Color Table'[Color])
RETURN SWITCH(TRUE(),
SizeColor = "Medium Green", "A",
SizeColor = "Large Red", "B",
BLANK())
i have database scheme like this.
# periode
+------+--------------+--------------+
| id | from | to |
+------+--------------+--------------+
| 1 | 2018-04-12 | 2018-05-11 |
| 2 | 2018-05-12 | 2018-06-11 |
+------+--------------+--------------+
# foo
+------+---------+
| id | name |
+------+---------+
| 1 | John |
| 2 | Doe |
| 3 | Trodi |
| 4 | son |
| 5 | Alex |
+------+---------+
#bar
+------+---------------+--------------+
| id | employee_id | periode_id |
+------+---------------+--------------+
| 1 | 1 |1 |
| 2 | 2 |1 |
| 3 | 1 |2 |
| 4 | 3 |1 |
+------+---------------+--------------+
I need to show employee that not in salary.
for now I do like this
queryset=Bar.objects.all().filter(periode_id=1)
result=Foo.objects.exclude(id=queryset)
but its fail, how do filter employee list not in salary?...
Well here you basically want the foos such that there is no period_id=1 in the Bar table.
We can let this work with:
ex = Bar.objects.all().filter(periode_id=1).values_list('employee_id', flat=True)
result=Foo.objects.exclude(id__in=ex)
I have two table looks like and I want to add column score to tableA from tableB, then get tableC, how to do in SAS?
the only rule is to add a column in tableA name "score " and its value is same as column "score" in tableB (which are all the same in tableB)
+----+---+---+---+
| id | b | c | d |
+----+---+---+---+
| 1 | 5 | 7 | 2 |
| 2 | 6 | 8 | 3 |
| 3 | 7 | 8 | 1 |
| 4 | 5 | 7 | 2 |
| 5 | 6 | 8 | 3 |
| 6 | 7 | 8 | 1 |
+----+---+---+---+
tableA
+---+---+-------+
| e | f | score |
+---+---+-------+
| 3 | 7 | 11 |
| 4 | 6 | 11 |
| 5 | 5 | 11 |
+---+---+-------+
tableB
+----+---+---+---+-------+
| id | b | c | d | score |
+----+---+---+---+-------+
| 1 | 5 | 7 | 2 | 11 |
| 2 | 6 | 8 | 3 | 11 |
| 3 | 7 | 8 | 1 | 11 |
| 4 | 5 | 7 | 2 | 11 |
| 5 | 6 | 8 | 3 | 11 |
| 6 | 7 | 8 | 1 | 11 |
+----+---+---+---+-------+
tableC
If the "id" is present in both tables, you can use the following to create Table C:
PROC SQL;
CREATE TABLE tableC AS
SELECT a.*, b.score
FROM tableA a JOIN tableB b
ON a.id = b.id;
QUIT;
Please confirm that this is what you need?