Skip to content

Commit

Permalink
Update documentation for PictureBinary function
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscar committed Apr 10, 2024
1 parent de69d29 commit c246a29
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 39 deletions.
4 changes: 2 additions & 2 deletions Functions/Date/DateTable.pq
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ let
<p><b>Date Table Generator</b></p>
<li><b>Creator: </b>Rick de Groot.</li>
<li><b>Web: </b>https://gorilla.bi/power-query/date-table/</li>
<li>------------------------------------------------------<\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/</li>
<li><b>LinkedIn: </b>https://www.linkedin.com/in/oscarmartinezv/</li>
<p>This function generates a date table with a range of dates from the start year to the end year.</p>
<p><b>Parameters:</b></p>
<ul>
Expand Down
110 changes: 73 additions & 37 deletions Functions/General/PictureBinary.pq
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)

0 comments on commit c246a29

Please sign in to comment.