I have a table in SNMP like this:
Id Name A.x A.y B.x B.y
1 Test 1 2 1 3
2 Next 3 4 5 6
I can make this accessible using SNMP as
table.1.1 = 1 table.1.2 = 2
table.2.1 = Name table.2.2 = Next
table.3.1 = 1 table.3.2 = 3
table.4.1 = 2 table.4.2 = 4
table.5.1 = 1 table.5.2 = 5
table.6.1 = 3 table.6.2 = 6
So the assignment of columns would be
1 = Id 2 = Name 3 = A.x 4 = A.y 5 = B.x 6 = B.y
However for some reasons (such as being able to add A.z and B.z later on in the "right order"), I want to have the columns as follows:
1 = Id 2 = Name 3.1 = A.x 3.2 = A.y 4.1 = B.x 4.2 = B.y
My data would then look like this:
table.1.1 = 1 table.1.2 = 2
table.2.1 = Name table.2.2 = Next
table.3.1.1 = 1 table.3.1.2 = 3
table.3.2.1 = 2 table.3.2.2 = 4
table.4.1.1 = 1 table.4.1.2 = 5
table.4.2.1 = 3 table.4.2.2 = 6
Basically SNMP (which only requires that all data can be iterated over with some start OID for every column and has no further internal rules for tables) allows that.
However can it be expressed in MIBs?
Are clients able to handle that?
You can do whatever you want. But, if you want to obey the "Structure of Management Information" standard RFC 2578, then section 7.1.12 Conceptual
Tables at
https://www.rfc-editor.org/rfc/rfc2578#section-7.1.12
explains the rules that you already know. Most apps will not know your ad-hoc table layout.
The assignments you propose, where some of your columnar objects are not direct sub-nodes of the row but instead have an intermediate sub-node between them, are not legal. The relevant rules are defined in RFC 2578 section 7.10(2), Mapping of the OBJECT-TYPE value:
(2) If the object corresponds to a conceptual row, then at least one
assignment, one for each column in the conceptual row, is present
beneath that object. The administratively assigned name for each
column is derived by appending a unique, positive sub-identifier to
the administratively assigned name for the conceptual row.
Emphasis mine. The meaning is clear: your columns' OIDs must be assigned by a single subidentifier appended to the row's OID (note that "name" means OBJECT IDENTIFIER value. The textual label one tends to think of as a name is called a "descriptor".)
Related
I have a list of int that represents service ids. and I want to make sure that all of those ids exist in the database.
In other words , I want to scan the list of ids and the table of services to make sure that all of these ids exist in the database.
I tried this :
List<int> ids;//[1,52]
var x = _context.Services.Any(s => ids.Contains(s.Id));//service ids = [1,2,3]
but it returned True , which is not the desired output.
I've also tried it this way :
_context.Services.Any(s => ids.Any(id => id == s.Id)!=null);
and this way
_context.Services.Any(s => ids.Any(id => id == s.Id)!=null);
with no luck as well. what is the right way to do it? I'm using EFCore 3.1.8
Normally you would use Queryable.Except for this.
If you have two sequence of items, and you do A except B, then if you have nothing left, then apparently every item from A is also an item in B.
IEnumerable<int> requiredIds = ...
IQueryable<int> serviceIds = dbContext.Services.Select(service => service.Id);
bool someRequiredIdsMissing = requiredIds.Except(serviceIds).Any();
Alas, your A is local and your B is in the database. So I guess this won't work.
What you can do, is to keep only Service Ids that are in the list of required Ids, and count them. If there are less, then apparently some requiredIds are not in serviceIds.
var requiredServiceIds = serviceIds.Where(serviceId => requiredIds.Contains(serviceId);
bool allRequiredAvailale = requiredServiceIds.Count() != requiredIds.Count();
Example:
IEnumerable<int> requiredIds = new [] {1, 2, 7, 20};
Total: 4 elements
Your service Ids are: 1 2 4 5 8 20 25
requiredServiceIds : 1 2 20: total 3 elements
So allRequiredAvailale is false;
Example 2:
Your service Ids are: 1 2 4 5 7 8 20 25
requiredServiceIds : 1 2 7 20: total 4 elements
So allRequiredAvailale is true;
This should be a very simple requirement. But it seems impossible to implement in DAX.
Data model, User lookup table joined to many "Cards" linked to each user.
I have a measure setup to count rows in CardUser. That is working fine.
<measureA> = count rows in CardUser
I want to create a new measure,
<measureB> = IF(User.boolean = 1,<measureA>, 16)
If User.boolean = 1, I want to return a fixed value of 16. Effectively, bypassing measureA.
I can't simply put User.boolean = 1 in the IF condition, throws an error.
I can modify measureA itself to return 0 if User.boolean = 1
measureA> =
CALCULATE (
COUNTROWS(CardUser),
FILTER ( User.boolean != 1 )
)
This works, but I still can't find a way to return 16 ONLY if User.boolean = 1.
That's easy in DAX, you just need to learn "X" functions (aka "Iterators"):
Measure B =
SUMX( VALUES(User.boolean),
IF(User.Boolean, [Measure A], 16))
VALUES function generates a list of distinct user.boolean values (1, 0 in this case). Then, SUMX iterates this list, and applies IF logic to each record.
I have a dataframe, df1, that reports courses students have taken, where ID is the student’s id, COURSES is a list of courses taken by the student, and TYPE and MAJOR are student attributes. The dataframe looks like this:
ID COURSES TYPE MAJOR
1 ['Intr To Archaeology', 'Statics', 'Circuits I…] Freshman EEEL
2 ['Signals & Systems I', ‘Instrumentation’…] Transfer EEEL
3 ['Keyboard Competence', 'Elementary … ] Freshman EEEL
4 ['Cultural Anthro', 'Vector Analysis’ … ] Freshma EEEL
I created a new dataframe, df2, that reports a dissimilarity measure for each pair of students based on the courses they’ve taken. df2 looks like this:
I created using the following script, but it runs very slowly (there are thousands of students). Can someone suggest a more efficient way to create df2?
One major problem is that the script below calculates the distance between (student 1 and student 2) and (student 2 and student 1), which is redundant since the distances are the same. However, the condition I created to prevent this:
if (id1 >= id2):
continue
doesn't work.
Entire script:
for id1, student1 in df.iterrows():
for id2, student2 in df.iterrows():
if (id1 >= id2):
continue
ID_1 = student1["ID"]
ID_2 = student2["ID"]
# courses as list strings
s1 = student1["COURSES"]
s2 = student2["COURSES"]
try:
# courses as sets
courses1 = set(ast.literal_eval(s1))
courses2 = set(ast.literal_eval(s2))
distance = float(len(courses1.symmetric_difference(courses2)))/(len(courses1) + len(courses2))
except:
# Some strings seem to have a different format
distance = -1
ID_1_Transfer = 1 if student1["TYPE"] == "Transfer" else 0
ID_2_Transfer = 1 if student2["TYPE"] == "Transfer" else 0
df2= df2.append({'ID_1': ID_1,'ID_2': PIDM_2,'Distance': distance, 'ID_1_Transfer': ID_1_Transfer, 'ID_2_Transfer': ID_2_Transfer}, ignore_index=True)
Here's the DB setup of 3 tables:
Template
-----------
TemplateId (Pk Identity)
Name
Example Data:
TemplateId Name
1 Homepage
2 Generic Landing Page
TemplateArea (Bridge table to keep track of each template type's list of areas)
----------------
TemplateAreaId (Pk Identity)
TemplateId (Fk)
AreaId (Fk)
Example Data:
TemplateAreaId TemplateId AreaId
1 1 1
2 1 2
3 1 3
4 2 1
5 2 2
So every template has 3 areas (you're seeing a set of templateIds (e.g. 2) and related set of AreaIds (1 & 2))
Area
-----
AreaId (Pk Name)
Name
Example Data:
AreaId Name
1 Top
2 Middle
3 Bottom
I'm trying to get a list of Areas based on a list of TemplateAreas keyed off of AreaId in my list of TemplateAreas:
so for example I should get this list of content areas for a TemplateId 2:
AreaId Name
1 Top
2 Middle
int templateId = 2;
List<TemplateArea> templateAreas = TemplateAreas.Where(ta => ta.TemplateId == templateId).ToList();
List<Area> areas = Areas.Where()); // this is where I'm stuck, how to get the list of areas (1 & 2) relatd to templateId 2
so in other words, get a list of Template Areas then get a list of related Areas keyed off of the specific TemplateId.
I'm basically trying to join to TemplateArea from Area on TemplateArea.TemplateId = templateId or something like that if this were T-SQL, e.g. Something like:
select AreaId, Name from Area join TemplateArea on Area.AreaId = TemplateArea.AreaId where TemplateArea.TemplateId = templateId
Using your code approach as a guide, you can join to the templateAreas:
List<Area> areas = Area.Join(templateAreas, a => a.AreaId, t => t.AreaId, (a, t) => a);
Try This :
List<Area> areas = Areas.Where(ta => ta.TemplateId == templateId).Select(ta => ta.Areas).ToList();
you can access any of the area field using this..
How about:
List<Area> areas = TemplateAreas.Where(ta => ta.TemplateId == templateId).Select(ta => ta.Areas).Distinct().ToList();
I am pretty sure this would work in Entity Framework, just not sure in Linq to Sql.
I have a table in SQL database:
ID Data Value
1 1 0.1
1 2 0.4
2 10 0.3
2 11 0.2
3 10 0.5
3 11 0.6
For each unique value in Data, I want to filter out the row with the largest ID. For example: In the table above, I want to filter out the third and fourth row because the fifth and sixth rows have the same Data values but their IDs (3) are larger (2 in the third and fourth row).
I tried this in Linq to Entities:
IQueryable<DerivedRate> test = ObjectContext.DerivedRates.OrderBy(d => d.Data).ThenBy(d => d.ID).SkipWhile((d, index) => (index == size - 1) || (d.ID != ObjectContext.DerivedRates.ElementAt(index + 1).ID));
Basically, I am sorting the list and removing the duplicates by checking if the next element has an identical ID.
However, this doesn't work because SkipWhile(index) and ElementAt(index) aren't supported in Linq to Entities. I don't want to pull the entire gigantic table into an array before sorting it. Is there a way?
You can use the GroupBy and Max function for that.
IQueryable<DerivedRate> test = (from d in ObjectContext.DerivedRates
let grouped = ObjectContext.DerivedRates.GroupBy(dr => dr.Data).First()
where d.Data == grouped.Key && d.ID == grouped.Max(dg => dg.ID)
orderby d.Data
select d);
Femaref's solution is interesting, unfortunately, it doesn't work because an exception is thrown whenever "ObjectContext.DerivedRates.GroupBy(dr => dr.Data).First()" is executed.
His idea has inspired me for another solution, something like this:
var query = from d in ObjectContext.ProviderRates
where d.ValueDate == valueDate && d.RevisionID <= valueDateRevision.RevisionID
group d by d.RateDefID into g
select g.OrderByDescending(dd => dd.RevisionID).FirstOrDefault();
Now this works.