Querying Shared Drive Permissions Hierarchy with Conditons in PowerBI - powerbi

My Original Data Structure Looks like this:
ID SecurityGroups_CLEAN EDIT_Drive.1 EDIT_Drive.2 READ_Drive.1 READ_Drive.2 DENY_Drive.1 DENY_Drive.2 DENY_Drive.3 Fullname_CLEAN
15 HighStaff L Drive null null null null null null Smith, John
17 Foreign_National null null null null L Drive M Drive Q Drive Smith, John
23 Domain Users U Drive 2 null L Drive Q Drive null null null Smith, John
After some transforming, filtering, pivoting, deleting columns etc... I've managed to get it to look like this....
Fullname_CLEAN Drive Count Permissions
Smith, John L Drive 3 DENY_Drive.1
Smith, John L Drive 3 EDIT_Drive.1
Smith, John L Drive 3 READ_Drive.1
Smith, John M Drive 1 DENY_Drive.2
Smith, John Q Drive 2 DENY_Drive.3
Smith, John Q Drive 2 READ_Drive.2
Smith, John U Drive 2 1 EDIT_Drive.1
Basically, I need to apply the following logic to summarize a users drive level permissions.
If a user belongs to a security group that has Deny permissions on a drive then regardless if another user group gives them Read or Edit permissions on this same drive their permission level is Deny.
If a user belongs to a security group that has Edit permissions on a drive then regardless of another user group gives them Read permissions on the same drive their permission level is Edit.
If a user belongs to a security group that has Read permissions on a drive then their Permission level is Read.
For a Final Output of:
Fullname_CLEAN Drive Permissions
Smith, John L Drive Deny
Smith, John M Drive Deny
Smith, John Q Drive Deny
Smith, John U Drive 2 Edit
Now, I realize that because of my sort and pure-ABC-coincidence I could just take the "min of an aggregated column" after grouping name and drive letter because Deny comes before Edit which comes before Read and this would mirror my conditions. However, I was hoping to learn the "right" way to do it.

Personally for this scenario I would leave it to ABC sort as there are fixed set of inputs and they already sort as required.
If you are imagining a different scenario or different inputs, then I would Add a Custom/Calculated Column with an "if ... then ... else if ..." statement that returns numeric equivalents, e.g.
= if [Permissions] = "Deny" then 0 else if [Permissions] = "Edit" then 1 else if [Permissions] = "Read" then 2 else 999

Related

String manipulation in google spreadsheet for getting city name and states from address

I am working on a google spreadsheet and I was stuck how to extract the second state name from the string.
MWE
A B C D
1 Address City State1 State2
2 Dublin,OH Dublin OH
3 Chicago,IL,NY Chicago IL NY
4 NY,Atlanta, DC Atlanta NY DC
5 Seattle,WA Seattle WA
From the address, how to get city, state1, and state2?
Link to the google sheet: https://docs.google.com/spreadsheets/d/10NzbtJhQj4hQBnZXcmwise3bLBIAWrE0qwSus_bz7a0/edit?usp=sharing
Notes
The state name is all caps.
There can be no second state.
In the spreadsheet you shared I entered in B1
={"City", "State1", "State2"; Arrayformula(if(len(A2:A), split(A2:A, ","),))}
See if that helps?
Suppose "Dublin, OH" from your post example list were in A2 with the others running from A3:A. Try this in B2 (making sure that B2:B is blank first):
=ArrayFormula(IF(A2:A="",,IF(IFERROR(REGEXEXTRACT(A2:A,"[A-Z]{2}")=REGEXEXTRACT(A2:A,".+([A-Z]{2})$"),TRUE),,IFERROR(REGEXEXTRACT(A2:A,".+([A-Z]{2})$")))))
The "plain-English version" of this reads as follows:
"If any cell in A2:A is blank, the corresponding cell in B2:B should also be blank. Otherwise, if the first instance of two juxtaposed capital letters is the same as the last instance of two juxtaposed capital letters, there is only one state present: leave that cell in Col B blank. Otherwise, pull the last such instance. If there are no instances of two juxtaposed capital letters for any test, instead of listing it as an error, list that as blank also."

Terraform templating question - iterating over a directory of variable files

Is it possible in Terraform to iterate over a directory of files containing variables and apply each file's values to a template? In very general, non-Terraform, bad pseudo-code -- here's what I'm hoping to do:
/varfiles/var_file1.yml
User:
Name: Jim
Address:
Street: 123 Main
City: MyTown
State: IL
Zip: 12345
Age: 40
Children:
- Beth
- Mike
/varfiles/var_file2.yml
User:
Name: Jill
Address:
Street: 321 Oak St
City: UrTown
State: IL
Zip: 54321
Age: 27
Children:
- Ricky
Template Logic
FOR each file in /varfiles/*(
print(User's name is: %{file.User.Name})
print(User's age is: %{file.User.Age})
print(User's address is: %{file.User.Street file.User.City, file.User.State file.User.Zip})})
IF COUNT(%{file.User.Children}) > 0 THEN (
FOR child in %{file.User.Children}(
print(The user has a child named: %{child})
)
)
)
Each iteration would be expected to generate a separate set of outputs - e.g. separate files.
Expected 'output' for var_file1.yml
User's name is: Jim
User's age is: 40
User's address is: 123 Main MyTown, IL 12345
The user has a child named: Beth
The user has a child named: Mike
Expected 'output' for var_file2.yml
User's name is: Jill
User's age is: 27
User's address is: 321 Oak Street UrTown, IL 54321
The user has a child named: Ricky
Solution doesn't have to implement this particular logic - but I'm not familiar enough with Terraform yet to know if it's possible at all, if this is the right approach, or if Terraform is the right tool.
The problem I'm hoping to solve is to template configuration files that would be generated on a per-user or per-role basis. Then store user or role-specific variables in separate files within a specific directory. This would make it easy to potentially manage hundreds of roles/users without having to deal with a var file that's hundreds or thousands of lines long and the dir structure and file names would make it obvious who/what was assigned what.

What data is saved in Hyperledger Fabric for the situation as explained below

Sarah sell USD50/lb to A and USD80/lb to B Now B should not be able to see Sarah and A's transaction... Correct me if I am wrong.
What data is saved in Sarah's blockchain, A's blockchain and B's Blockchain??
///////////
Transaction1 : Sarah to A-- USD50
Transaction2 : Sarah to B-- USD80
/////////
Sarah:
Transaction hash 1 and 2
Details of transaction (USD50 for A and USD80 for B)
A:
Transaction Hash 1 and 2
Details of transaction(USD50 for sarah,no information of transaction2 )
B:
Transaction hash 1 and 2
Details of transaction(USD80 for sarah, no info of Transaction1 )
Correct if I am wrong? Does this way things work?
There are two main options. Utilize channels so that separate ledgers are created, or embed access security in the Smart Contract so only the parties to a transaction can view it.

Using Perl to extract text from a text file

I have a question related to using regex to pull out data from a text file. I have a text file in the following format:
REPORTING-OWNER:
OWNER DATA:
COMPANY CONFORMED NAME: DOE JOHN
CENTRAL INDEX KEY: 99999999999
FILING VALUES:
FORM TYPE: 4
SEC ACT: 1934 Act
SEC FILE NUMBER: 811-00248
FILM NUMBER: 11530052
MAIL ADDRESS:
STREET 1: 7 ST PAUL STREET
STREET 2: STE 1140
CITY: BALTIMORE
STATE: MD
ZIP: 21202
ISSUER:
COMPANY DATA:
COMPANY CONFORMED NAME: ACME INC
CENTRAL INDEX KEY: 0000002230
IRS NUMBER: 134912740
STATE OF INCORPORATION: MD
FISCAL YEAR END: 1231
BUSINESS ADDRESS:
STREET 1: SEVEN ST PAUL ST STE 1140
CITY: BALTIMORE
STATE: MD
ZIP: 21202
BUSINESS PHONE: 4107525900
MAIL ADDRESS:
STREET 1: 7 ST PAUL STREET SUITE 1140
CITY: BALTIMORE
STATE: MD
ZIP: 21202
I want to save the owner's name (John Doe) and identifier (99999999999) and the company's name (ACME Inc) and identfier (0000002230) as separate variables. However, as you can see, the variable names (CENTRAL INDEX KEY and COMPANY CONFORMED NAME) are exactly the same for both pieces of information.
I've used the following code to extract the owner's information, but I can't figure out how to extract the data for the company. (Note: I read the entire text file into $data).
if($data=~m/^\s*CENTRAL\s*INDEX\s*KEY:\s*(\d*)/m){$cik=$1;}
if($data=~m/^\s*COMPANY\s*CONFORMED\s*NAME:\s*(.*$)/m){$name=$1;}
Any idea as to how I can extract the information for both the owner and the company?
Thanks!
There is a big difference between doing it quick and dirty with regexes (maintenance nightmare), or doing it right.
As it happens, the file you gave looks very much like YAML.
use YAML;
my $data = Load(...);
say $data->{"REPORTING-OWNER"}->{"OWNER DATA"}->{"COMPANY CONFORMED NAME"};
say $data->{"ISSUER"}->{"COMPANY DATA"}->{"COMPANY CONFORMED NAME"};
Prints:
DOE JOHN
ACME INC
Isn't that cool? All in a few lines of safe and maintainable code ☺
my ($ownname, $ownkey, $comname, $comkey) = $data =~ /\bOWNER DATA:\s+COMPANY CONFORMED NAME:\s+([^\n]+)\s*CENTRAL INDEX KEY:\s+(\d+).*\bCOMPANY DATA:\s+COMPANY CONFORMED NAME:\s+([^\n]+)\s*CENTRAL INDEX KEY:\s+(\d+)/ms
If you're reading this file on a UNIX operating system but it was generated on Windows, then line endings will be indicated by the character pair \r\n instead of just \n, and in this case you should do
$data =~ tr/\r//d;
first to get rid of these \r characters and prevent them from finding their way into $ownname and $comname.
Select both bits of information at the same time so that you know that you're getting the CENTRAL INDEX KEY associated with either the owner or the company.
($name, $cik) = $data =~ /COMPANY\s+CONFORMED\s+NAME:\s+(.+)$\s+CENTRAL\s+INDEX\s+KEY:\s+(.*)$/m;
Instead of trying to match elements in the string, split it into lines, and parse properly into data structure that will let such searches be made easily, like:
$data->{"REPORTING-OWNER"}->{"OWNER DATA"}->{"COMPANY CONFORMED NAME"}
That should be relatively easy to do.
Search for OWNER DATA: read one more line, split on : and take the last field. Same for COMPANY DATA: header (sortof), on so on

Vim: Parsing address fields from all around the globe

Intro
This post is long, but I consider it thorough. I hope this post might be helpful (addresses) to others while teaching complex VIM regexes. Thank you for your time.
Worldwide addresses:
American, Canadian and a few other countries are offered 5 fields on a form, which is then displayed in a comma delimited format that I need to further dissect. Ideally, the comma-separated content looks like:
Some Really Nice Place, 111 Street, Beautiful Town, StateOrProvince, zip
where zip can be either a series of just numbers (US) or numbers and letters (Canada).
Invariably, people throw an extra comma into their text box field input and that adds some complexity to the parsing of this data. For example:
Some Really Nice Place, 111 Street, suite 101, Beautiful Town, StateOrProvince, zip
Further complicating this parse is that the data from non-US and non-Canadian countries contains an extra comma-delimited field that was somehow provided to them - adding a place for them to enter their country. (No, there is no "US" or "Canada" field for their entries. So, it's "in addition" to the original 5 comma-delimited fields.) Such as:
Foreign Name of Building, A street name, A City, ,zip, Country
The ",," is usually empty as non-US countries do are not segmented into states. And, yes, the same "additional commas" as described above happens here too.
Foreign Name of Building, cross streets, district, A street name, A City, ,zip, Country
Parsing Strategy:
A country name will never include a digit, whereas a US or Canadian zip will always have at least some digits. If you go backwards using this assumption about the contents of the last field then you should be able to place the country, zip, State (if not empty ",,"), City and Street into their respect positions - which are the most important fields to get right. Anything beyond those sections could be lumped together in the first or or two lines as descriptions of the address (i.e. building, name, suite, cross streets, etc). For example:
Some Really Nice Place, 111 Street, suite 101, Beautiful Town, Lovely State, Digits&Letters
Last section has a digit (therefore a US or Canadian address)
There a total of 6 sections, so that's one more than the original 5
Knowing that sections 5-2 are zip, state, town, address...
6 minus 5 (original) = add an extra Address (Address2) field and leave the first section as the header, resulting in:
Header: Some Really Nice Place, Address1: 111 Street, Address2: Suite 101, Town: Beautiful Town, State/Province: Lovely State, Zip: Digits&Letters
Whereas there might be a discrepancy on where "111 Street" or "Suite 101" goes (Address1 or Address2), it at least gets the zip, state, city and address(s) lumped together and leaves the first section as the "Header" to the email address for data entry purposes.
Under this approach, foreign address get parsed like:
Foreign Name of Building, cross streets, district, A street name, A
City, ,zip, Country
Last section has no digit, so it must be a Country
That means, moving right to left, the second section is the zip
So now (foreign) you have an "original 6 sections" to subtract from the total of 7 in the example
7th section = country, 6th = zip, 5th = state (mostly blank on foreign address), 4th = City, 3rd = address1, 2nd = address2, 1st = header
We knew to use two address fields because the example had 7 sections and foreign addresses have a base of 6 sections. Any number of sections above the base are added to a second address2 field. If there are 3 sections above the base section count then they are appended to each inside the address2 field.
Coding
In this approach using VIM, how would I initially read the number of comma-delimited sections (after I've captured the entire address in a register)? How do I do submatch(es) on a series of comma-delimited sections for which I am not sure the number of sections that exist?
Example Addresses
Here are some practice address (US and Foreign) if you are so inclined to help:
City Gas & Electric - Bldg 4, 222 Middle Park Ct, CP4120F, Dallas, Texas, 44984
MHG Engineering, Inc. Suite 200, 9899 Balboa Ave, San Diego, California, 92123-1502
SolarWind Turbines, 2nd Floor Conference Room, 2300 Ruffin Road, Seattle, Washington, 84444
123 Aeronautics, 2239 Industry Parkway, Salt Lake City, Utah, 55344
Ongwanda Gov't Resources, 6000 Portsmouth Avenue, Ottawa, Ontario, K7M 8A6
Graylang Seray Center, 6600 Haig Rd, Singapore, , 437848, Singapore
Lot 459, Block 14, Jalan Sultan Tengah, Petra Jaya, Kuching, , 93050, Malaysia
Virtual Steel, 1 Umgazi Rd Aspec Park, Pretoria, , 0075, South Africa
Idiom Towers South, Fifth Floor, Jasmen Conference Room, 1500 Freedom Street, Pretoria, , 0002, South Africa
The following code is a draft-quality Vim script (hopefully) implementing the
address parsing routine described in the question.
function! ParseAddress(line)
let r = split(a:line, ',\s*', 1)
let hadcountry = r[-1] !~ '\d'
let a = {}
let a.country = hadcountry ? r[-1] : ''
let r = r[:-1-hadcountry]
let a.zip = r[-1]
let a.state = r[-2]
let a.city = r[-3]
let a.header = r[0]
let nleft = len(r) - 4
if hadcountry
let a.address1 = r[-4]
let a.address2 = join(r[1:nleft-1], ', ')
else
let a.address1 = r[1]
let a.address2 = join(r[2:nleft], ', ')
endif
return a
endfunction
function! FormatAddress(a)
let t = map([
\ ['Header', 'header'],
\ ['Address 1', 'address1'],
\ ['Address 2', 'address2'],
\ ['Town', 'city'],
\ ['State/Province', 'state'],
\ ['Country', 'country'],
\ ['Zip', 'zip']],
\ 'has_key(a:a, v:val[1]) && !empty(a:a[v:val[1]])' .
\ '? v:val[0] . ": " . a:a[v:val[1]] : ""')
return join(filter(t, '!empty(v:val)'), '; ')
endfunction
The command below can be used to test the above parsing routines.
:g/\w/call setline(line('.'), FormatAddress(ParseAddress(getline('.'))))
(One can provide a range to the :global command to run it through fewer
number of test address lines.)
Maybe you should review some of the other questions about addresses around the world. The USA and Canada are extraordinarily systematic with their systems; most other countries are a lot less rigorous about the approved formats. Anything you devise for the USA and Canada will run into issues almost immediately you deal with other addresses.
Best practices for storing postal addresses in a database
Is there a common street address database design for all addresses of the world
How many address fields would you use for a UK address
ISO Standard Street Addresses
There are probably other related questions: see the tag street-address for some of them.