-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update documentation for PictureBinary function
- Loading branch information
Oscar
committed
Apr 10, 2024
1 parent
de69d29
commit c246a29
Showing
2 changed files
with
75 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,75 @@ | ||
let | ||
picresult = (InputTable as table, InputBinaryZBPosition as number, InputKeyZBPosition as number ) as table => | ||
let | ||
//Get list of files in folder | ||
Source = (InputTable), | ||
//Converts table that contians image to list | ||
ListToInput = Table.ToRows(Source), | ||
//Creates Splitter function | ||
SplitTextFunction = Splitter.SplitTextByRepeatedLengths(30000), | ||
//Function to convert binary of photo to multiple | ||
ConvertOneFile = (InputRow as list) => | ||
let | ||
BinaryIn = InputRow{InputBinaryZBPosition}, | ||
ID = InputRow{InputKeyZBPosition}, | ||
BinaryText = Binary.ToText(BinaryIn, BinaryEncoding.Base64), | ||
SplitUpText = SplitTextFunction(BinaryText), | ||
AddFileName = List.Transform(SplitUpText, each {ID,_}) | ||
// Define metadata for the function, describing its purpose and usage. | ||
metaDocumentation = type function ( | ||
InputTable as (type table meta [ | ||
Documentation.FieldCaption = "Select table with binary files", | ||
Formatting.IsMultiLine = false, | ||
Formatting.IsCode = false | ||
]), | ||
InputBinaryZBPosition as (type number meta [ | ||
Documentation.FieldCaption = "Binary column zero-based position", | ||
Documentation.SampleValues = {0}, | ||
Formatting.IsMultiLine = false, | ||
Formatting.IsCode = false | ||
]), | ||
InputKeyZBPosition as (type number meta [ | ||
Documentation.FieldCaption = "Key column zero-based position", | ||
Documentation.SampleValues = {0}, | ||
Formatting.IsMultiLine = false, | ||
Formatting.IsCode = false | ||
]) | ||
) as any meta [ | ||
Documentation.Name = "Pictures Binaries to Base64", | ||
Documentation.LongDescription = | ||
//This is the description of the documentation, it only accepts a handful of HTML tags for formatting. | ||
" | ||
<p><b>Pictures Binaries to Base64</b></p> | ||
<li><b>Creator: </b>Chris Webb and Patrick LeBlanc.</li> | ||
<li>This YouTube video from Guy in a Cube explain the usage of the function: https://youtu.be/Q82yzcfkqAc?si=aSsNYwwU1usWw94o</li> | ||
<li>------------------------------------------------------</li> | ||
<li><b>Editor: </b>Oscar Martinez.</li> | ||
<li><b>Web: </b>https://bibb.pro</li> | ||
<li><b>LinkedIn: </b>https://www.linkedin.com/in/oscarmartinezv/</li> | ||
|
||
<p>This function converts binary image files in the InputTable to base64 format. It splits the binary data into smaller chunks and adds the corresponding key value from the InputTable to each chunk. </p> | ||
<p>The function takes three parameters:</p> | ||
<ul> | ||
<li><b>InputTable: </b>Select table with binary files.</li> | ||
<li><b>InputBinaryZBPosition: </b>Binary column zero-based position.</li> | ||
<li><b>InputKeyZBPosition: </b>Key column zero-based position.</li> | ||
</ul> | ||
<p>The result is a table with two columns: ID (key value) and Pic (base64 encoded image data). The base64 encoded data can now be stitched back with DAX</p> | ||
" | ||
], | ||
// Define the main function | ||
myFunction = (InputTable as table, InputBinaryZBPosition as number, InputKeyZBPosition as number ) as table => | ||
let | ||
//Get list of files in folder | ||
Source = (InputTable), | ||
//Converts table that contians image to list | ||
ListToInput = Table.ToRows(Source), | ||
//Creates Splitter function | ||
SplitTextFunction = Splitter.SplitTextByRepeatedLengths(30000), | ||
//Function to convert binary of photo to multiple | ||
ConvertOneFile = (InputRow as list) => | ||
let | ||
BinaryIn = InputRow{InputBinaryZBPosition}, | ||
ID = InputRow{InputKeyZBPosition}, | ||
BinaryText = Binary.ToText(BinaryIn, BinaryEncoding.Base64), | ||
SplitUpText = SplitTextFunction(BinaryText), | ||
AddFileName = List.Transform(SplitUpText, each {ID,_}) | ||
in | ||
AddFileName, | ||
//Loops over all photos and calls the above function | ||
ConvertAllRows = List.Transform(ListToInput, each ConvertOneFile(_)), | ||
//Combines lists together | ||
CombineLists = List.Combine(ConvertAllRows), | ||
//Converts results to table | ||
ToTable = #table(type table[ID=text,Pic=text],CombineLists), | ||
//Adds index column to output table | ||
AddIndexColumn = Table.AddIndexColumn(ToTable, "Index", 0, 1) | ||
in | ||
AddFileName, | ||
//Loops over all photos and calls the above function | ||
ConvertAllRows = List.Transform(ListToInput, each ConvertOneFile(_)), | ||
//Combines lists together | ||
CombineLists = List.Combine(ConvertAllRows), | ||
//Converts results to table | ||
ToTable = #table(type table[ID=text,Pic=text],CombineLists), | ||
//Adds index column to output table | ||
AddIndexColumn = Table.AddIndexColumn(ToTable, "Index", 0, 1) | ||
in | ||
AddIndexColumn, | ||
documentation = [ | ||
Documentation.Name = " PictureBinary", | ||
Documentation.Description = "Returns the base64 encoded binary of a picture, broken in 30K chunks, in a table which can be later stitched via DAX", | ||
Documentation.Category = "File Operations", | ||
Documentation.Source = "", | ||
Documentation.Version = " 1.0 ", | ||
Documentation.Author = "Oscar Martínez" | ||
] | ||
in | ||
Value.ReplaceType(picresult, Value.ReplaceMetadata(Value.Type(picresult), documentation)) | ||
AddIndexColumn | ||
in | ||
// Apply the function metadata to myFunction. | ||
Value.ReplaceType(myFunction, metaDocumentation) |