Array sum of second column

517
5
Jump to solution
01-20-2023 01:24 AM
kelin84
New Contributor III

Hi, I'm a bit confused here. 

In my CSV table I have a usage column and a floor height for that usage (just like the tutorial) 

Printing the usages
attr Testusages = [usages_data[0:numUsages-1,0],usages_data[0:numUsages-1,1]]

I receive:
(10x2)
Residential              3,6576
Office                       3,9624
Business                   4,572
Parking                     3,048
Education                3,9624
Sports                       7
Cultural                    4,572
Research                  3,048
Health                       4,572

The attribute:
@Enum(valuesAttr=Testusages)
attr floor_usages = stringArray()

is not showing the usage chosen + is height, it only shows the Usage. So if I print that one I get:
(10)[Residential,Parking,Residential,Residential,Residential,Sports,Residential,Residential,Business,Residential]

I want to calculate the sum of the height and pass it through as a value through my rule, depending on the floor usage chosen.

So if I could just pass the second row in the CSV, I would expect that I could do a sum() and then I would have the total height of the chosen usages.

But how to??

 

Thanks.

 

0 Kudos
1 Solution

Accepted Solutions
kelin84
New Contributor III

Thank you again Jonas for your answers, that is much appreciated. I realized that I couldn't explain my thoughts. I started to write a response to your last post, but it was messy writing.

The basic is that I wanted to use the floors_usages as a ratio and not a per floor kind of thing. If the building percentage allowed med to create 10 floors, I would use that as an input, and the 2 usage types for example, those would both have 5 floors each. That would have been easy, if it wasn't because the different usages had different heights. I was for sure going in the wrong direction, so it wasn't as complicated as I made it out to be:

buildingFootprint(buildingarea,lotArea) -->
	createFloors(rint(transect*lotArea/buildingarea))

createFloors(floorCount) -->

Recs(rint(floorCount/size(floor_usages)),0,size(floor_usages))

Recs(noFloors,arrayIdx,arraySize) -->
case arrayIdx == arraySize : NIL
else :
	extrude(getFloorHeight(floor_usages[arrayIdx])*noFloors)
		comp(f) {top : Recs(noFloors,arrayIdx+1,arraySize) | side : Something(noFloors,arrayIdx,arraySize)}
	

Something(noFloors,arrayIdx,arraySize) -->
split(y) {getFloorHeight(floor_usages[arrayIdx]) :
color(getUsageColor(floor_usages[arrayIdx])) X.}* 

 
So this is solved, but will still look at making it a bit more optimized.

 

Thanks.

View solution in original post

0 Kudos
5 Replies
JonasObertuefer
Esri Contributor

Hi @kelin84,

Can't you just calculate the total height like this

const totalHeight = sum(floatArray(usages_data[0:numUsages-1,1]))

and then make use of it whenever you need in your rule?

Cheers,
Jonas

0 Kudos
kelin84
New Contributor III

Thank you Jonas, as far as I understand this will give the total of the array, and not the total of the chosen usages. 

Where I don't find any issues in showing only the chosen usage types in a filtered array, since that is done by the attribute selection:

So I want the same functionality as the floor usages:
(4)[Residential,Residential,Residential,Business]

just with the floor height, without choosing it as an attribute.

case floor_usages == "Residential" : 3,5

case floor_usages == "business" : 5

(4)[Residential,Residential,Residential,Business]

(4)[3.5,3.5,3.5,5]

buildingHeight == 15,5

If that make sense?

Right now I'm getting a stringArray of the of the selected floor usages. The attributes that I'm able to choose is from the CSV, and is filtered to only show the usages.

This attribute writes both usages and floor height of the full CSV

attr Testusages = [usages_data[0:numUsages-1,0],usages_data[0:numUsages-1,1]]
(9x2)
   Residential   3,6576
        Office   3,9624
      Business    4,572
       Parking    3,048
     Education   3,9624
        Sports        7
      Cultural    4,572
      Research    3,048
        Health    4,572

but the attrubute for choosing usages are only passing through the first column:

@Enum(valuesAttr=Testusages)
attr floor_usages = stringArray()

=

(5)[Residential,Residential,Residential,Business,Residential]

 

My idea was to add

take the array it creates and filter on the second column

like:

print(sum(floor_usages[0:numUsages-1,1]))

 

Thanks.

0 Kudos
JonasObertuefer
Esri Contributor

Hi again,

So you want to choose by usage height and not by usage type in the inspector? Or do you just want to know the final height of the building?

For the later I would use report:

// edited Assign_Floor_Usages_03.cga

FloorMass(floorInd) -->
	Reports(floor_usages[floorInd], getUsageColor(floor_usages[floorInd]), getFloorHeight(floor_usages[floorInd]))
	extrude(getFloorHeight(floor_usages[floorInd]))
	color(getUsageColor(floor_usages[floorInd]))
	s('1, '0.95, '1)
	FloorMass.
	
Reports(myUsage, myUsageColor, myFloorHeight) -->
	report("GFA." + myUsage, geometry.area)
	report("GFA." + myUsage + "#color", myUsageColor)
	report("Building Height", myFloorHeight)
	NIL

 

 

kelin84
New Contributor III

Thank you again Jonas for your answers, that is much appreciated. I realized that I couldn't explain my thoughts. I started to write a response to your last post, but it was messy writing.

The basic is that I wanted to use the floors_usages as a ratio and not a per floor kind of thing. If the building percentage allowed med to create 10 floors, I would use that as an input, and the 2 usage types for example, those would both have 5 floors each. That would have been easy, if it wasn't because the different usages had different heights. I was for sure going in the wrong direction, so it wasn't as complicated as I made it out to be:

buildingFootprint(buildingarea,lotArea) -->
	createFloors(rint(transect*lotArea/buildingarea))

createFloors(floorCount) -->

Recs(rint(floorCount/size(floor_usages)),0,size(floor_usages))

Recs(noFloors,arrayIdx,arraySize) -->
case arrayIdx == arraySize : NIL
else :
	extrude(getFloorHeight(floor_usages[arrayIdx])*noFloors)
		comp(f) {top : Recs(noFloors,arrayIdx+1,arraySize) | side : Something(noFloors,arrayIdx,arraySize)}
	

Something(noFloors,arrayIdx,arraySize) -->
split(y) {getFloorHeight(floor_usages[arrayIdx]) :
color(getUsageColor(floor_usages[arrayIdx])) X.}* 

 
So this is solved, but will still look at making it a bit more optimized.

 

Thanks.

0 Kudos
JonasObertuefer
Esri Contributor

Glad you make it work and cool to see your adaption of the csv example 🙂

Just from a quick look at your snippet: You might can get rid of Recs() and do everything in createFloors(). In general if you do more complex calculations which you might use multiple times consider writing it as a function .

I marked your post as a solution.

Best,
Jonas

0 Kudos