I am using NDepend 2018.1.1. and I need to obtain the namespace of the target of the following NDepend Query
//
// <Name>Relevant Methods</Name>
//
let e9 = "Sys.Core.App.CommonService"
let e10 = "Sys.Core.App.CommonService3GProvider"
let e17 = "Sys.Core.App.UnderwritingService3GProvider"
let e18 = "Sys.Core.App.UniquePerson.Actions"
let e19 = "Sys.Core.App.UniquePerson"
let e1 = "Sys.Co.Application.UnderwritingService"
let e2 = "Sys.Co.Application.UnderwritingService3GProvider"
let e3 = "Sys.Core.App.Accounting.Services"
let e4 = "Sys.Core.App.Accounting.Services.Provider"
let e5 = "Sys.Core.App.BillingService"
let e6 = "Sys.Core.App.BillingService3GProvider"
let e7 = "Sys.Core.App.ClaimsService"
let e8 = "Sys.Core.App.ClaimsService3GProvider"
let e11 = "Sys.Core.App.EventsService"
let e12 = "Sys.Core.App.EventsService3GProvider"
let e13 = "Sys.Core.App.IntegrationService"
let e14 = "Sys.Core.App.IntegrationService3GProvider"
let e15 = "Sys.Core.App.SecurityServices"
let e16 = "Sys.Core.App.UnderwritingService"
/**/
let ensamblados = from m in
Assemblies.WithName(e1).Concat(
Assemblies.WithName(e2)).Concat(
Assemblies.WithName(e3)).Concat(
Assemblies.WithName(e4)).Concat(
Assemblies.WithName(e5)).Concat(
Assemblies.WithName(e6)).Concat(
Assemblies.WithName(e9)).Concat(
Assemblies.WithName(e10)).Concat(
Assemblies.WithName(e11)).Concat(
Assemblies.WithName(e12)).Concat(
Assemblies.WithName(e13)).Concat(
Assemblies.WithName(e14)).Concat(
Assemblies.WithName(e15)).Concat(
Assemblies.WithName(e16)).Concat(
Assemblies.WithName(e17)).Concat(
Assemblies.WithName(e18)).Concat(
Assemblies.WithName(e19))
select m
//Obtain the types and members of the assemblies
from dest in ensamblados
let targets = dest.ChildTypesAndMembers.ToHashSetEx()
let methodsUser = Application.Methods.UsingAny(targets)
let typesUser = Application.Types.UsingAny(targets)
//Search all the sources that call any of the targets Type or Members
//Concatenar los metodos y los tipos de orig
let results = from orig in methodsUser //.Concat((IEnumerable<IMember>)typesUser)
// HERE need to obtain the namespace of the target of the following
select new {
orig
,t=orig.FullName
,NumRefAlOrig = orig.IsMethod ? orig.AsMethod.MethodsCalled.Intersect(targets).Concat(orig.AsMethod.FieldsUsed.Intersect(targets)).Count() :
orig.AsType.TypesUsed.Intersect(targets).Count()
,OrigenEsMetodo= orig.IsMethod
,OrigenTipo= orig.IsMethod ? "Metodo":"Tipo"
}
/*Metodos*/
from rr in results
where rr.OrigenEsMetodo
select rr
I have tried different methods from the NDepend framework but this is my first NDepende Query and I feel that I am missing something very obvious
First you can simplify by writing
let ensamblados = from m in
Assemblies.WithNameIn(
"Sys.Co.Application.UnderwritingService",
"Sys.Co.Application.UnderwritingService3GProvider",...)
or
let ensamblados = from m in
Assemblies.WithNameLike("Sys.Co.Application.")
.Concat( Assemblies.WithNameLike("Sys.Core.App.")
We'll complete this answer when the question will be clearer
Related
I want to get nTh char from target1 or target2 but using a reference char of abc String.
But result2 is not working as expected...
let abc = "abcde"
let target1 = "12345"
let target2 = "🅐🅑🅒🅓🅔"
let m = abc.firstIndex(of: "c")!
let result1 = target1[m] //want "3" //working
let result2 = target2[m] //want "🅒" //not working
String subscripting is a pretty bad idea, but if you insist on using it, you have to use distance and offset, not an absolute index. Like this:
let abc = "abcde"
let target1 = "12345"
let target2 = "🅐🅑🅒🅓🅔"
let d = abc.distance(from: abc.startIndex, to: abc.firstIndex(of: "c")!)
let result1 = target1[target1.index(target1.startIndex, offsetBy:d)]
let result2 = target2[target2.index(target2.startIndex, offsetBy:d)]
I am trying to set a value for "background color" as seen below but when I print the value after setting it, it simply shows nil? This makes absolutely no sense. Please help, I have exhausted all resources already.
Thank you.
let request = GTLRSheets_Request.init()
request.repeatCell = GTLRSheets_RepeatCellRequest.init()
let colbox = GTLRSheets_GridRange.init()
colbox.startRowIndex = rowstart
colbox.endRowIndex = rowend
colbox.startColumnIndex = columnstart
colbox.endColumnIndex = columnend
request.repeatCell?.range = colbox
let color = GTLRSheets_Color.init()
color.blue = 60
color.red = 47
color.green = 77
request.repeatCell?.cell?.userEnteredFormat?.backgroundColor = color
request.repeatCell?.cell?.userEnteredFormat?.textFormat?.bold = true
request.repeatCell?.cell?.userEnteredFormat?.horizontalAlignment = "CENTER"
request.repeatCell?.fields = "userEnteredFormat(backgroundColor,textFormat,horizontalAlignment)"
print(request.repeatCell?.cell?.userEnteredFormat?.backgroundColor)
let batchUpdate = GTLRSheets_BatchUpdateSpreadsheetRequest.init()
batchUpdate.requests = [request]
let createQuery = GTLRSheetsQuery_SpreadsheetsBatchUpdate.query(withObject: batchUpdate, spreadsheetId: spreadsheetId)
service.executeQuery(createQuery) { (ticket, result, NSError) in
}
Issue:
You should initialize cell and userEnteredFormat.
Solution:
cell refers to an instance of GTLRSheets_CellData, and should be initialized the following way:
request.repeatCell?.cell = GTLRSheets_CellData.init()
userEnteredFormat refers to an instance of GTLRSheets_CellFormat:
request.repeatCell?.cell?.userEnteredFormat = GTLRSheets_CellFormat.init()
Reference:
GTLRSheets_CellData
GTLRSheets_CellFormat
Swift: Initialization
I am working on project that writes to google sheets. I am trying to Unmerge cells. This function works however it unmerges everything in the sheet. This is because it is not setting the .range value. When I print (as seen below) the "test" value all range values are shown accordingly however when I print the "request.unmergeCells?.range" it says nil. I am further confused as I use this exact code elsewhere for a merge command and it loads the values fine (see second snippet of code.)
I have tried for days to resolve this issue with no avail. Any thoughts?
func unmergecell1() {
let request = GTLRSheets_Request.init()
let test = GTLRSheets_GridRange.init()
rowstart = 4
rowend = 100
columnstart = 0
columnend = 100
test.startRowIndex = rowstart
test.endRowIndex = rowend
test.startColumnIndex = columnstart
test.endColumnIndex = columnend
request.unmergeCells?.range = test
request.unmergeCells = GTLRSheets_UnmergeCellsRequest.init()
print("=========unmerge==============")
print(test)
print(request.unmergeCells?.range)
let batchUpdate = GTLRSheets_BatchUpdateSpreadsheetRequest.init()
batchUpdate.requests = [request]
let createQuery = GTLRSheetsQuery_SpreadsheetsBatchUpdate.query(withObject: batchUpdate, spreadsheetId: spreadsheetId)
service.executeQuery(createQuery) { (ticket, result, NSError) in
}
}
func mergecell() {
let request = GTLRSheets_Request.init()
request.mergeCells = GTLRSheets_MergeCellsRequest.init()
let test = GTLRSheets_GridRange.init()
test.startRowIndex = rowstart
test.endRowIndex = rowend
test.startColumnIndex = columnstart
test.endColumnIndex = columnend
request.mergeCells?.range = test
request.mergeCells?.mergeType = kGTLRSheets_MergeCellsRequest_MergeType_MergeRows
let batchUpdate = GTLRSheets_BatchUpdateSpreadsheetRequest.init()
batchUpdate.requests = [request]
let createQuery = GTLRSheetsQuery_SpreadsheetsBatchUpdate.query(withObject: batchUpdate, spreadsheetId: spreadsheetId)
service.executeQuery(createQuery) { (ticket, result, NSError) in
}
}
I think you need to switch these 2 lines:
request.unmergeCells?.range = test
request.unmergeCells = GTLRSheets_UnmergeCellsRequest.init()
The 2nd line initates the unmerge request, and only after you initate it can you add the range to it. So by making it the other way round, as below, it should work.
request.unmergeCells = GTLRSheets_UnmergeCellsRequest.init()
request.unmergeCells?.range = test
I want to be able to add the player's data the "to-one" part of the many relationships. The fetch does some aggregation for me, but I would like to know what player it belongs to.
I have a CoreData model that looks like the following:
I have a fetch request that looks like the following:
func statsPerPlayer(player: Players, managedContext: NSManagedObjectContext) -> [String: Int] {
var resultsDic = [String: Int]()
let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "Shifts")
let predicate = NSPredicate(format: "playersRelationship = %#", player)
fetchRequest.predicate = predicate
let nsExpressionForKeyPath = NSExpression(forKeyPath: "timeOnIce")
let nsExpressionForFunctionMin = NSExpression(forFunction: "min:", arguments: [nsExpressionForKeyPath])
let nsExpressionDescriptionMin = NSExpressionDescription()
nsExpressionDescriptionMin.expression = nsExpressionForFunctionMin
nsExpressionDescriptionMin.name = "minShift"
nsExpressionDescriptionMin.expressionResultType = .integer16AttributeType
let nsExpressionForFunctionMax = NSExpression(forFunction: "max:", arguments: [nsExpressionForKeyPath])
let nsExpressionDescriptionMax = NSExpressionDescription()
nsExpressionDescriptionMax.expression = nsExpressionForFunctionMax
nsExpressionDescriptionMax.name = "maxShift"
nsExpressionDescriptionMax.expressionResultType = .integer16AttributeType
let nsExpressionForFunctionSum = NSExpression(forFunction: "sum:", arguments: [nsExpressionForKeyPath])
let nsExpressionDescriptionSum = NSExpressionDescription()
nsExpressionDescriptionSum.expression = nsExpressionForFunctionSum
nsExpressionDescriptionSum.name = "sumShift"
nsExpressionDescriptionSum.expressionResultType = .integer16AttributeType
let nsExpressionForFunctionAvg = NSExpression(forFunction: "average:", arguments: [nsExpressionForKeyPath])
let nsExpressionDescriptionAvg = NSExpressionDescription()
nsExpressionDescriptionAvg.expression = nsExpressionForFunctionAvg
nsExpressionDescriptionAvg.name = "avgShift"
nsExpressionDescriptionAvg.expressionResultType = .integer16AttributeType
let nsExpressionForFunctionCount = NSExpression(forFunction: "count:", arguments: [nsExpressionForKeyPath])
let nsExpressionDescriptionCount = NSExpressionDescription()
nsExpressionDescriptionCount.expression = nsExpressionForFunctionCount
nsExpressionDescriptionCount.name = "countShift"
nsExpressionDescriptionCount.expressionResultType = .integer16AttributeType
fetchRequest.propertiesToFetch = [nsExpressionDescriptionMin, nsExpressionDescriptionMax, nsExpressionDescriptionSum, nsExpressionDescriptionAvg, nsExpressionDescriptionCount]
fetchRequest.resultType = .dictionaryResultType
do {
let fetchArray = try managedContext.fetch(fetchRequest)
print(fetchArray)
resultsDic = fetchArray.first as! [String : Int]
} catch let error as NSError {
print("\(self) -> \(#function): Could not fetch. \(error), \(error.userInfo)")
}
return resultsDic
} //statsPerPlayer
The results look great and something like this:
[{
avgShift = 39;
countShift = 4;
maxShift = 89;
minShift = 6;
sumShift = 157;
}]
However, I would like to include the player that this data is for. How do I add the "to-one" part of the one-to-many relationship in the results?
Thanks!!
In your code above, just add the relevant relationship name to the properties to fetch:
fetchRequest.propertiesToFetch = ["playersRelationship", nsExpressionDescriptionMin, nsExpressionDescriptionMax, nsExpressionDescriptionSum, nsExpressionDescriptionAvg, nsExpressionDescriptionCount]
The dictionaries that are returned will then include the key "playersRelationship" with value set to the NSManagedObjectID of the corresponding Players object. You can then use the context's object(with:) method to access the Players object itself.
Update
So after some testing, it turns out:
a) CoreData gets confused regarding the count aggregate function if you include the relationship in the propertiesToFetch. That leads to the Invalid keypath (request for aggregate operation on a toOne-only keypath error.
b) CoreData gets confused for all the other aggregate functions if you include the relationship in the propertiesToFetch. (It calculates the aggregate across every object, not just those matching the predicate.)
The solution to both problems is to add the relationship as a GROUP BY property. CoreData then calculates the aggregates correctly and also correctly recognises count as a valid operation. So, add the following line:
fetchRequest.propertiesToGroupBy = ["playersRelationship"]
How can I calculate IR temperature in CC2650.
TI Temperature : F000AA00-0451-4000-B000-000000000000
Temperature Data: f000aa01-0451-4000-b000-000000000000
I try to calculate object and ambient based on data in Temperature Data characteristic. Object data is higher then IR temperature showed in TI application.
Swift Code:
static func calculateObjectAndAmbient(objectRaw:Int16, ambientRaw:Int16) -> (Double, Double)
{
let ambient = Double(ambientRaw)/128.0;
let vObj2 = Double(objectRaw)*0.00000015625;
let tDie2 = ambient + 273.15;
let s0 = 6.4*pow(10,-14);
let a1 = 1.75*pow(10,-3);
let a2 = -1.678*pow(10,-5);
let b0 = -2.94*pow(10,-5);
let b1 = -5.7*pow(10,-7);
let b2 = 4.63*pow(10,-9);
let c2 = 13.4;
let tRef = 298.15;
let s = s0*(1+a1*(tDie2 - tRef)+a2*pow((tDie2 - tRef),2));
let vOs = b0 + b1*(tDie2 - tRef) + b2*pow((tDie2 - tRef),2);
let fObj = (vObj2 - vOs) + c2*pow((vObj2 - vOs),2);
let object = pow(pow(tDie2,4) + (fObj/s),0.25) - 273.15;
return (object, ambient)
}
I also want to calculate MPU9250Service data.
Service = "F000AA80-0451-4000-B000-000000000000"
Characteristic Data = "F000AA81-0451-4000-B000-000000000000"
Characteristic Config = "F000AA82-0451-4000-B000-000000000000"
Is there a manual ? I would like to access Gyro., Accel., Magn., data.
Sorry about my english.
Thank you in advance.
Calculation of Object and Ambient is changed in CC2650.
So new swift calculations in here if anyone needed;
static func calculateObjectAndAmbient(objectRaw:Int16, ambientRaw:Int16) -> (Double, Double)
{
let SCALE_LSB = 0.03125;
let a = objectRaw >> 2;
let Obj = Double(a) * SCALE_LSB
let b = ambientRaw >> 2;
let Amb = Double(b) * SCALE_LSB
return (Obj, Amb)
}
More Details : sensortag2015
More Details : TI Wiki