Some Strange Fault (In My Model Record ?) - elm

My compiler complains about two values:
model.firstChord.fifth and model.secondChord.fifth
in this excerpt:
-- render frets
renderFret : Model -> Fret -> Html Msg
renderFret model fret =
let
( pitchName, pitchLevel ) = fret.pitch
( firstChordRootPitchName, firstChordRootPitchLevel ) = model.firstChord.root
( firstChordThirdPitchName, firstChordThirdPitchLevel ) = model.firstChord.third
( firstChordFifthPitchName, firstChordFifthPitchLevel ) = model.firstChord.fifth
( secondChordRootPitchName, secondChordRootPitchLevel ) = model.secondChord.root
( secondChordThirdPitchName, secondChordThirdPitchLevel ) = model.secondChord.third
( secondChordFifthPitchName, secondChordFifthPitchLevel ) = model.secondChord.fifth
in
...
it tells me:
model.firstChord does not have a field named fifth. - The type of model.firstChord is:
Maybe Chord
Which does not contain a field named fifth.
but my model has a field fifth:
-- initial model
init : ( Model, Cmd Msg )
init =
(
{ firstChord =
Just
{ root = ( "C", 3 )
, third = ( "E", 3 )
, fifth = ( "G", 3 )
}
, secondChord =
Just
{ root = ( "F", 3 )
, third = ( "A", 3 )
, fifth = ( "C", 4 )
}
}
,
Cmd.none
)
The type of the chord is:
-- chords
type alias Chord =
{ root : Pitch
, third : Pitch
, fifth : Pitch
}
Each pitch has this type:
-- pitch
type alias Pitch = ( PitchName, PitchLevel )
-- pitch name
type alias PitchName = String
-- pitch level
type alias PitchLevel = Int
Where could be the problem?
Thank you.

Compile error says exactly what the problem is
Maybe Chord is either Just Chord or Nothing. None of these two contain a field named fifth.
In order to make this work you need to make sure that model.firstChord and model.secondChord are Just Chord:
-- render frets
renderFret : Model -> Fret -> Html Msg
renderFret model fret =
case (model.firstChord, model.secondChord) of
(Just firstChord, Just secondChord) ->
let
( pitchName, pitchLevel ) = fret.pitch
( firstChordRootPitchName, firstChordRootPitchLevel ) = firstChord.root
( firstChordThirdPitchName, firstChordThirdPitchLevel ) = firstChord.third
( firstChordFifthPitchName, firstChordFifthPitchLevel ) = firstChord.fifth
( secondChordRootPitchName, secondChordRootPitchLevel ) = secondChord.root
( secondChordThirdPitchName, secondChordThirdPitchLevel ) = secondChord.third
( secondChordFifthPitchName, secondChordFifthPitchLevel ) = model.secondChord.fifth
in
...
_ ->
-- here is something when either `model.firstChord` or `model.secondChord` is `Nothing`
By using pattern matching (Just firstChord, Just secondChord), firstChord and secondChord expressions appear to be of type Chord, which has a field named fifth

You have not provied your Model, but in your init function you have declared the chord as a Maybe. If the compiler was happy with that, then it means your model also includes the Maybes. As a first solution, remove the Justs, but also look at your Model
init =
(
{ firstChord =
Just
{ root = ( "C", 3 )
, third = ( "E", 3 )
, fifth = ( "G", 3 )
}
, secondChord =
Just <-------- Here you say that secondChord is Maybe Chord
{ root = ( "F", 3 )
, third = ( "A", 3 )
, fifth = ( "C", 4 )
}
}
,
Cmd.none
)

Related

Date Table created with M is imported as an Expression

I am using SSAS Tabular 2019 and I have had no problem in loading my views or tables, but this time instead of loading a Date table from SQL Server I created my own Date table using custom M code, but it appears that the date table is being imported as an Expression and not as a table. Here is a screenshot:
Here is my M code:
let
Source = ( StartDate as date, EndDate as date ) as table =>
let
DateTable =
let
StartDateNumber = Number.From ( Date.StartOfYear ( StartDate ) ),
EndDateNumber = Number.From ( Date.AddYears ( Date.EndOfYear ( EndDate ), 1 ) ),
DateList = { StartDateNumber..EndDateNumber },
ToTable = Table.FromList ( DateList, Splitter.SplitByNothing() ),
ToDateType = Table.TransformColumnTypes ( ToTable, { "Column1", type date } ),
RenameToDate = Table.RenameColumns ( ToDateType, { "Column1", "Date" } )
in
RenameToDate,
// Day related fields are created here
Day_Fields =
let
Add_Day_Name = Table.AddColumn ( DateTable, "Weekday Name", each Date.DayOfWeekName ( [Date] ), type text ),
Add_Day_Number = Table.AddColumn ( Add_Day_Name, "Weekday Number", each Date.DayOfWeek ( [Date] ), Int64.Type )
in
Add_Day_Number,
// Month related fields are created here
Month_Fields =
let
Add_Month_Name = Table.AddColumn ( Day_Fields, "Month Name", each Date.MonthName ( [Date] ), type text ),
Add_Month_Number = Table.AddColumn ( Add_Month_Name, "Month Number", each Date.Month ( [Date] ), Int64.Type ),
Add_Month_Initials = Table.AddColumn ( Add_Month_Number, "Month Initials", each Text.Start ( [Month Name], 3 ), type text )
in
Add_Month_Initials,
// Year Related Fields are Create Here
Year_Fields =
let
Add_Year = Table.AddColumn ( Month_Fields, "Calendar Year Number", each Date.Year ( [Date] ), Int64.Type ),
Add_Year_Text = Table.AddColumn ( Add_Year, "Calendar Year", each "CY " & Text.From ( Date.Year ( [Date] ) ), type text )
in
Add_Year_Text
in
Year_Fields
in
Source
Can you please confirm what is happening here?

subrequest in case return error on clickhouse

So i try a make a view , actually this is my code :
drop table if exists computed_datum_hours_base;
create view computed_datum_hours_base
as select
toStartOfHour(datetime_value) as datetime_desc,
computed_id,
computed_kind,
computed_type,
case
when computed_type = 'intensive' then avg(value)
when computed_type = 'extensive.some' then sum(value)
when computed_type = 'extensive.differential' then
(
select value as value_f from ref_computed_datum
where ref_computed_id = computed_id
and ref_computed_kind = computed_kind
and ref_computed_type = computed_type
and ref_datetime_value = toStartOfHour(addHours(datetime_value, 1))
) - (
select value as value_f from ref_computed_datum
where ref_computed_id = computed_id
and ref_computed_kind = computed_kind
and ref_computed_type = computed_type
and ref_datetime_value = toStartOfHour(datetime_value)
)
end as value,
count(uuid) as nb_value
from computed_datum
join ref_computed_datum
on computed_id = ref_computed_id
and computed_kind = ref_computed_kind
and computed_type = ref_computed_type
where uuid = ref_uuid
group by
computed_id,
computed_kind,
computed_type,
toStartOfHour(datetime_value)
;
my issue is on the case for extensive.differential ...
clickhouse say he can found the column for computed_id ... like the subrequest is scoped and didn't have access to the colum from the main requeste ...
So this is another bug of clickhouse ?
Or there are a reel scope and i can't do this like this ...
( so How can do this ? )
Edit: full error
Code: 47, e.displayText() = DB::Exception: Missing columns: 'datetime_value' 'computed_kind' 'computed_type' 'computed_id' 'value' while processing query: 'SELECT value AS value_f FROM api_client.ref_computed_datum WHERE (ref_computed_id = computed_id) AND (ref_computed_kind = computed_kind) AND (ref_computed_type = computed_type) AND (ref_datetime_value = toStartOfHour(addHours(datetime_value, 1)))', required columns: 'value' 'computed_id' 'ref_computed_id' 'ref_computed_kind' 'computed_type' 'ref_computed_type' 'computed_kind' 'ref_datetime_value' 'datetime_value', source columns: 'ref_flags' 'ref_computed_kind' 'ref_computed_id' 'ref_datetime_value' 'ref_computed_type' 'ref_EventDateTime' 'ref_insert' 'ref_value' 'ref_uuid' (version 20.4.2.9 (official build))
computed_datum folow this structure :
EventDateTime DateTime default now(),
insert String,
uuid String default generateUUIDv4(),
datetime_value DateTime,
computed_id Int32,
computed_kind String,
computed_type String,
value Float64,
flags String
```
I make a ref view that only prefix all colum with ref_ for making a walkaround about the alias bug.
At this time clickhouse didn't support correlated query ...
cf: https://github.com/ClickHouse/ClickHouse/issues/6697

DAX expression for ROW_NUMBER() PARTITION BY ORDER BY equivalent

I have a SQL statement like this:
(ROW_NUMBER() OVER (PARTITION BY a.[market], [MEASURE_TYPE]
ORDER BY AM, REP, ORDER_KEY)) AS ORDER_KEY
I want to write a DAX to implement the above SQL statement.
This is not as simple in DAX as in SQL. Here is an example:
Order Key Within Partition =
VAR CurrentMarket = [Market]
VAR CurrentMeasureType = [MeasureType]
VAR CurrentAM = [AM]
VAR CurrentREP = [REP]
VAR CurrentOrderKey = [OrderKey]
VAR CurrentPartition = FILTER (
a, -- the table name
[Market] = CurrentMarket
&& [MeasureType] = CurrentMeasureType
)
RETURN SUMX (
CurrentPartition,
IF (
ISONORAFTER (
CurrentAM, [AM], ASC,
CurrentREP, [REP], ASC,
CurrentOrderKey, [OrderKey], ASC
),
1
)
)
EDIT: Power Query would be better to achieve this.
let
/* Steps so far */
Source = ...,
...
a = ...,
/* End of steps so far */
/* Add steps below to add Order Key Within Partition column */
Partitions = Table.Group(
a,
{"Market", "MeasureType"}, {"Partition", each _}
)[Partition],
AddedOrderKeys = List.Transform(
Partitions,
each Table.AddIndexColumn(
Table.Sort(_, {"AM", "REP", "OrderKey"}),
"Order Key Within Partition",
1
)
),
Result = Table.Combine(AddedOrderKeys)
in
Result
I contribute with an alternative solution to the RANKX. The answer containing the Power Query is the correct one because avoid using calculated columns.
Sales[Sequence by Customer] =
VAR CurrentDate = Sales[Date]
VAR CurrentTime = Sales[Time]
RETURN COUNTROWS (
    FILTER (
        CALCULATETABLE (
            Sales,
            ALLEXCEPT ( Sales, Sales[Customer] )
        ),
        Sales[Date] < CurrentDate
          || ( Sales[Date] = CurrentDate
               && Sales[Time] <= CurrentTime )
    )
)
Source

Odoo add records to one2many field using onchange event twice

As code below , I could add record to the one2many field 'f_12m' when the other field 'onte' was changed .
But the problem is that when I change the 'note' value again , it delete all the records of 'f_12m' field , then add a new record .
How can i keep the old records and add new one , without saving the whold model ?
f_12m = fields.One2many( 'x_app.other_model', 'oid', string= 'FieldName' )
#api.onchange( 'note' )
def _onchange_note( self ) :
dic_value = {}
list_f_12m = []
list_f_12m.append( ( 0 , 0 , {'note':self.note} ) )
dic_value.update( f_12m = list_f_12m )
return {'value': dic_value }
Please try below code
f_12m = fields.One2many( 'x_app.other_model', 'oid', string= 'FieldName' )
#api.onchange( 'note' )
def _onchange_note( self ) :
dic_value = {}
list_f_12m = self.f_12m.ids
f_12m_new = self.env['x_app.other_model'].create({'note':self.note, 'oid':self.id})
list_f.12m.append(f_12m_new.id)
self.f_12m = [(6,0,list_f_12m)]
Hope this helps!

Conditional statements in PIG

I have below input in a text file and need to generate output in another file based on the logic.
Here is my input file:
customerid|Dateofsubscription|Customercode|CustomerType|CustomerText
1001|2017-05-23|455|CODE|SPRINT56
1001|2017-05-23|455|DESC|Unlimited Plan
1001|2017-05-23|455|DATE|2017-05-05
1002|2017-05-24|455|CODE|SPRINT56
1002|2017-05-24|455|DESC|Unlimited Plan
1002|2017-05-24|455|DATE|2017-05-06
Logic:
If Customercode = 455
if( CustomerType = "CODE" )
Val= CustomerText
if( CustomerType = "DESC" )
Description = CustomerText
if( CustomerType = "DATE" )
Date = CustomerText
Output:
customerid|Val|Description|Date
1001|SPRINT56|Unlimited Plan|2017-05-05
1002|SPRINT56|Unlimited Plan|2017-05-06
Could you please help me with this.
rawData = LOAD data;
filteredData = FILTER rawData BY (Customercode == 455);
--Extract and set Val/Description/Date based on CustomerText and 'null' otherwise
ExtractedData = FOREACH filteredData GENERATE
customerId,
(CustomerType == "CODE" ? CustomerText : null) AS Val,
(CustomerType == "DESC" ? CustomerText : null) AS Description,
(CustomerType == "DATE" ? CustomerText : null) AS Date;
groupedData = GROUP ExtractedData BY customerId;
--While taking MAX, all 'nulls' will be ignored
finalData = FOREACH groupedData GENERATE
group as CustomerId,
MAX($1.Val) AS Val,
MAX($1.Description) AS Description,
MAX($1.Date) AS Date;
DUMP finalData;
I have specified the core logic. Loading, formatting and storage should be straight-forward.
Filter the input where customercode=455,generate the required 2 columns,then group by customerid and then use BagToString
.
B = FILTER A BY Customercode == 455;
C = FOREACH B GENERATE $0 as CustomerId,$4 as CustomerText;
D = GROUP C BY CustomerId;
E = FOREACH D GENERATE group AS CustomerId, BagToString(C.CustomerText, '|'); -- Note:This will generate 1001,SPRINT56|Unlimited Plan|2017-05-05 so,you will have to concat the first field with '|' and then concat the resulting field with the second field which is already delimited by '|'.
F = FOREACH E GENERATE CONCAT(CONCAT($0,'|'),$1);
DUMP F;