Skip to content

Commit

Permalink
Fixes a few bits... (#11581)
Browse files Browse the repository at this point in the history
- Minor fixes from past PR.
- Always use Table viz for Table.
- Fix display to `Always`  for any AWS required parameters.
- Add widget for `Redshift` credentials and alter `Username_And_Password` to require arguments.
- Fix display in `Data` module methods for required parameters.
- Fix `Statistic.bulk_widget`.
- Alter `Google_Analytics` so credentials the first parameter.
- Add support for storing the credential file in Enso cloud in `Google_Analytics`.

![image](https://github.com/user-attachments/assets/f34c4231-9f9f-468b-90e9-bbc7f2374d22)
  • Loading branch information
jdunkerley authored Nov 18, 2024
1 parent 6b810ee commit d5f0e9e
Show file tree
Hide file tree
Showing 16 changed files with 106 additions and 67 deletions.
1 change: 1 addition & 0 deletions distribution/lib/Standard/AWS/0.0.0-dev/src/AWS.enso
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ type AWS

Arguments:
- uri: The URI to resolve.
@uri (Text_Input display=..Always)
resolve_region_and_service : URI -> AWS_Region_Service
resolve_region_and_service (uri:URI=(Missing_Argument.throw "uri")) =
region_regex = regex "^(([a-z]{2}-[^.]+?-\d+)|(global))$"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ type AWS_Credential
to_display_text self -> Text = self.to_text.to_display_text

## PRIVATE
default_widget (display : Display = ..When_Modified) -> Widget =
default_widget (add_user_password:Boolean=False) (display : Display = ..When_Modified) -> Widget =
default = Option "Default" "..Default"
profile = Option "Profile" "..Profile" [["profile", make_single_choice AWS_Credential.profile_names]]
key = Option "Key" "..Key" [["access_key_id", make_text_secret_selector], ["secret_access_key", make_text_secret_selector]]
user_password = if add_user_password then [Option "Username_And_Password" "..Username_And_Password"] else []
with_config = Option "With_Configuration" "..With_Configuration"
Widget.Single_Choice values=[default, profile, key, with_config] display=display
Widget.Single_Choice values=[default, profile, key, with_config]+user_password display=display
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ type Redshift_Details
- use_ssl: Whether to use SSL (defaults to `SSL_Mode.Require`).
- client_cert: The client certificate to use or `Nothing` if not needed.
@host (Text_Input display=..Always)
Redshift (host:Text=(Missing_Argument.throw "host")) (port:Integer=5439) (schema:Text='') (db_user:Text='') (credentials:Credentials|AWS_Credential=AWS_Credential.Profile) (use_ssl:SSL_Mode=..Require) (client_cert:Client_Certificate|Nothing=Nothing)
@credentials AWS_Credential.default_widget add_user_password=True
Redshift
host:Text=(Missing_Argument.throw "host")
port:Integer=5439
schema:Text=''
db_user:Text=''
credentials:Credentials|AWS_Credential=..Profile
use_ssl:SSL_Mode=..Require
client_cert:Client_Certificate|Nothing=Nothing

## PRIVATE
Attempt to resolve the constructor.
Expand Down
3 changes: 3 additions & 0 deletions distribution/lib/Standard/AWS/0.0.0-dev/src/S3/S3.enso
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from Standard.Base import all
import Standard.Base.Errors.Common.Missing_Argument
import Standard.Base.Metadata.Widget.Text_Input
import Standard.Base.Network.HTTP.Response_Body.Response_Body
import Standard.Base.System.File_Format_Metadata.File_Format_Metadata
import Standard.Base.System.Input_Stream.Input_Stream
Expand Down Expand Up @@ -71,6 +72,7 @@ list_buckets credentials:AWS_Credential=..Default = handle_s3_errors <|
- If the bucket does not exist, an `S3_Bucket_Not_Found` error is thrown.
- If more items are available than the `max_count` parameter, a
`More_Records_Available` warning is attached to the result.
@bucket (Text_Input display=..Always)
@credentials AWS_Credential.default_widget
list_objects : Text -> Text -> AWS_Credential -> Integer -> Vector S3_File ! S3_Error
list_objects (bucket : Text = Missing_Argument.throw "bucket") prefix:Text="" credentials:AWS_Credential=..Default max_count:Integer=1000 =
Expand Down Expand Up @@ -126,6 +128,7 @@ get_object bucket key credentials:AWS_Credential=AWS_Credential.Default delimite
`AWS_SDK_Error` will be raised.
- If the bucket does not exist, an `S3_Bucket_Not_Found` error is thrown.
- If the object does not exist, an `S3_Key_Not_Found` error is thrown.
@bucket (Text_Input display=..Always)
@credentials AWS_Credential.default_widget
head : Text -> Text -> AWS_Credential -> Dictionary Text Any ! S3_Error
head (bucket : Text = Missing_Argument.throw "bucket") key:Text="" credentials:AWS_Credential=..Default =
Expand Down
8 changes: 4 additions & 4 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data.enso
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ from project.System.File_Format import Auto_Detect, File_Format
import Standard.Examples

example_xls_to_table = Data.read Examples.xls (..Sheet 'Dates')
@path Text_Input
@path (Text_Input display=..Always)
@format File_Format.default_widget
read : Text | URI | File -> File_Format -> Problem_Behavior -> Any ! File_Error
read path=(Missing_Argument.throw "path") format=Auto_Detect (on_problems : Problem_Behavior = ..Report_Warning) = case path of
Expand Down Expand Up @@ -138,7 +138,7 @@ read path=(Missing_Argument.throw "path") format=Auto_Detect (on_problems : Prob

files = Data.list name_filter="*.csv"
example_csv_dir_to_table = Data.read_many files
@paths (Vector_Editor item_editor=Text_Input item_default='""')
@paths (Vector_Editor item_editor=Text_Input item_default='""' display=..Always)
@format File_Format.default_widget
read_many : Many_Files_List -> File_Format -> Return_As -> Problem_Behavior -> Any ! File_Error
read_many (paths : Many_Files_List = Missing_Argument.throw "paths") format=Auto_Detect return=..Vector (on_problems : Problem_Behavior = ..Report_Warning) =
Expand Down Expand Up @@ -170,7 +170,7 @@ read_many (paths : Many_Files_List = Missing_Argument.throw "paths") format=Auto
import Standard.Examples

example_read = Data.read_text Examples.csv_path
@path Text_Input
@path (Text_Input display=..Always)
@encoding Encoding.default_widget
read_text : (Text | File) -> Encoding -> Problem_Behavior -> Text
read_text path=(Missing_Argument.throw "path") (encoding : Encoding = Encoding.default) (on_problems : Problem_Behavior = ..Report_Warning) =
Expand Down Expand Up @@ -228,7 +228,7 @@ read_text path=(Missing_Argument.throw "path") (encoding : Encoding = Encoding.d

example_list_files =
Data.list Examples.data_dir name_filter="**.md" recursive=True
@directory Folder_Browse
@directory (Folder_Browse display=..Always)
@name_filter File_Format.name_filter_widget
list : Text | File -> Text -> Boolean -> Vector File
list (directory:(Text | File)=enso_project.root) (name_filter:Text="") recursive:Boolean=False =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import project.Runtime.Ref.Ref
from project.Data.Boolean import Boolean, False, True
from project.Data.Range.Extensions import all
from project.Errors.Common import Unsupported_Argument_Types
from project.Metadata import Choice, Widget
from project.Metadata import Choice, Display, Widget

polyglot java import java.lang.NullPointerException
polyglot java import org.enso.base.CompareException
Expand Down Expand Up @@ -133,11 +133,10 @@ type Statistic

## PRIVATE
Bulk widget for Statistic.
bulk_widget : Widget
bulk_widget =
bulk_widget display:Display=..When_Modified -> Widget =
options = ["Count", "Minimum", "Maximum", "Sum", "Product", "Mean", "Variance", "Standard_Deviation", "Skew", "Kurtosis", "Covariance", "Pearson", "Spearman", "R_Squared"].map n-> Choice.Option n ".."+n
items = Widget.Single_Choice options
Widget.Vector_Editor items "..Count"
Widget.Vector_Editor items "..Count" display=display

## PRIVATE
Gets the order needed to compute a statistic for a moment based statistic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Vector.compute self statistic:Statistic=..Count =

Arguments:
- statistics: Set of statistics to calculate.
@statistics Statistic.bulk_widget
@statistics (Statistic.bulk_widget display=..Always)
Vector.compute_bulk : Vector Statistic -> Vector Any
Vector.compute_bulk self statistics:Vector=[..Count, ..Sum] =
Statistic.compute_bulk self statistics
Expand All @@ -41,7 +41,7 @@ Vector.running self statistic:Statistic=..Count =

Arguments:
- statistics: Set of statistics to calculate.
@statistics Statistic.bulk_widget
@statistics (Statistic.bulk_widget display=..Always)
Vector.running_bulk : Vector Statistic -> Vector Any
Vector.running_bulk self (statistics:(Vector Statistic)=[..Count, ..Sum]) =
Statistic.running_bulk self statistics
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from Standard.Base import all
import Standard.Base.Errors.Common.Missing_Argument
import Standard.Base.Metadata.Display
import Standard.Base.Metadata.Widget
from Standard.Base.Metadata.Choice import Option
Expand All @@ -7,9 +8,11 @@ from Standard.Base.Widget_Helpers import make_text_secret_selector

type Credentials
## Simple username and password type.
@username make_text_secret_selector
@password make_text_secret_selector
Username_And_Password username:(Text|Enso_Secret) password:(Text|Enso_Secret)
@username (make_text_secret_selector display=..Always)
@password (make_text_secret_selector display=..Always)
Username_And_Password
username:(Text|Enso_Secret)=(Missing_Argument.throw "username")
password:(Text|Enso_Secret)=(Missing_Argument.throw "password")

## PRIVATE
Override `to_text` to mask the password field.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from Standard.Base import all
import Standard.Base.Data.Array_Proxy.Array_Proxy
import Standard.Base.Errors.Common.Missing_Argument
from Standard.Base.Metadata import make_single_choice, Widget
from Standard.Base.Metadata import Display, make_single_choice, Widget
from Standard.Base.Metadata.Choice import Option
from Standard.Base.Metadata.Widget import Single_Choice, Text_Input, Vector_Editor

Expand Down Expand Up @@ -34,14 +34,14 @@ type Google_Analytics
- credentials: The Google credentials to use. Default is to use the
Google Application Default Credentials in the environment variables.
See https://cloud.google.com/docs/authentication/application-default-credentials
@credentials (Google_Credential.default_widget display=..Always)
@property Google_Analytics_Property.default_widget
@dimensions _make_dimensions_vector_selector
@metrics _make_metrics_vector_selector
@start_date _make_start_date_widget
@end_date (Date.default_widget include_today=True)
@credentials Google_Credential.default_widget
read : Google_Analytics_Property -> (Vector Text) -> (Vector Text) -> Date -> Date -> Google_Credential -> Table
read property:Google_Analytics_Property=(Missing_Argument.throw "property") dimensions:Vector=['country'] metrics:Vector=['activeUsers'] start_date:Date=(Date.today.previous ..Year) end_date:Date=Date.today credentials:Google_Credential=..Default -> Table =
read : Google_Credential -> Google_Analytics_Property -> (Vector Text) -> (Vector Text) -> Date -> Date -> Table
read credentials:Google_Credential=(Missing_Argument.throw "credentials") property:Google_Analytics_Property=(Missing_Argument.throw "property") dimensions:Vector=['country'] metrics:Vector=['activeUsers'] start_date:Date=(Date.today.previous ..Year) end_date:Date=Date.today -> Table =
case credentials of
Google_Credential.Sample -> _read_sample_data dimensions metrics start_date end_date
_ ->
Expand All @@ -60,7 +60,7 @@ type Google_Analytics
See https://cloud.google.com/docs/authentication/application-default-credentials
- limit: The maximum number of accounts to read. Default is 1000.
- include_deleted: Whether to include deleted accounts. Default is false.
@credentials Google_Credential.default_widget
@credentials (Google_Credential.default_widget display=..Always)
@limit Rows_To_Read.default_widget
list_accounts : Google_Credential -> Rows_To_Read -> Boolean -> Vector
list_accounts credentials:Google_Credential=..Default (limit : Rows_To_Read = ..First_With_Warning 1000) include_deleted:Boolean=False -> Vector =
Expand All @@ -82,11 +82,11 @@ type Google_Analytics
See https://cloud.google.com/docs/authentication/application-default-credentials
- limit: The maximum number of accounts to read. Default is 1000.
- include_deleted: Whether to include deleted accounts. Default is false.
@account Google_Analytics_Account_Filter.default_widget
@credentials Google_Credential.default_widget
@account Google_Analytics_Account_Filter.default_widget
@limit Rows_To_Read.default_widget
list_properties : Google_Analytics_Account_Filter -> Google_Credential -> Rows_To_Read -> Boolean -> Vector
list_properties account:Google_Analytics_Account_Filter=..All_Accounts credentials:Google_Credential=..Default (limit : Rows_To_Read = ..First_With_Warning 1000) include_deleted:Boolean=False -> Vector =
list_properties : Google_Credential -> Google_Analytics_Account_Filter -> Rows_To_Read -> Boolean -> Vector
list_properties credentials:Google_Credential=..Default account:Google_Analytics_Account_Filter=..All_Accounts (limit : Rows_To_Read = ..First_With_Warning 1000) include_deleted:Boolean=False -> Vector =
java_credentials = credentials.as_java
to_read = limit.rows_to_read.if_nothing 0
filter = account.as_java
Expand All @@ -103,10 +103,10 @@ type Google_Analytics
- credentials: The Google credentials to use. Default is to use the
Google Application Default Credentials in the environment variables.
See https://cloud.google.com/docs/authentication/application-default-credentials
@credentials (Google_Credential.default_widget display=..Always)
@property Google_Analytics_Property.default_widget
@credentials Google_Credential.default_widget
list_metrics : Google_Analytics_Property -> Google_Credential -> Vector
list_metrics property:Google_Analytics_Property=(Missing_Argument.throw "property") credentials:Google_Credential=..Default -> Vector =
list_metrics : Google_Credential -> Google_Analytics_Property -> Vector
list_metrics credentials:Google_Credential=(Missing_Argument.throw "credentials") property:Google_Analytics_Property=(Missing_Argument.throw "property") -> Vector =
java_credentials = credentials.as_java
array = _handle_google_error <| GoogleAnalyticsReader.listMetrics java_credentials property.java_record
array.if_not_error <| array.map record-> Google_Analytics_Field.Metric record
Expand All @@ -119,35 +119,36 @@ type Google_Analytics
- credentials: The Google credentials to use. Default is to use the
Google Application Default Credentials in the environment variables.
See https://cloud.google.com/docs/authentication/application-default-credentials
@credentials (Google_Credential.default_widget display=..Always)
@property Google_Analytics_Property.default_widget
@credentials Google_Credential.default_widget
list_dimensions : Google_Analytics_Property -> Google_Credential -> Vector
list_dimensions property:Google_Analytics_Property=(Missing_Argument.throw "property") credentials:Google_Credential=..Default -> Vector =
list_dimensions : Google_Credential -> Google_Analytics_Property -> Vector
list_dimensions credentials:Google_Credential=(Missing_Argument.throw "credentials") property:Google_Analytics_Property=(Missing_Argument.throw "property") -> Vector =
java_credentials = credentials.as_java
array = _handle_google_error <| GoogleAnalyticsReader.listDimensions java_credentials property.java_record
array.if_not_error <| array.map record-> Google_Analytics_Field.Dimension record


## PRIVATE
private _make_metrics_vector_selector self_arg cache -> Widget =
private _make_metrics_vector_selector self_arg cache display:Display=..Always -> Widget =
_ = self_arg
items = Panic.catch Any handler=p->[p.payload.to_display_text] <|
property = cache.if_not_nothing <| cache "property"
property.if_not_nothing <|
credentials = cache.if_not_nothing <| cache "credentials"
Google_Analytics.list_metrics property credentials . map f-> Option (f.apiName + " (" + f.category + ")") f.apiName.pretty
Google_Analytics.list_metrics (credentials.if_nothing Google_Credential.Default) property . map f-> Option (f.api_name + " (" + f.category + ")") f.api_name.pretty
item_editor = make_single_choice (items.if_nothing ['activeUsers', 'bounceRate', 'conversions', 'newUsers', 'sessionsPerUser', 'userConversionRate'])
Vector_Editor item_editor=item_editor item_default=item_editor.values.first.value display=..Always
Widget.Vector_Editor item_editor=item_editor item_default=item_editor.values.first.value display=display

## PRIVATE
private _make_dimensions_vector_selector self_arg cache -> Widget =
private _make_dimensions_vector_selector self_arg cache display:Display=..Always -> Widget =
_ = self_arg
items = Panic.catch Any handler=p->[p.payload.to_display_text] <|
property = cache.if_not_nothing <| cache "property"
property.if_not_nothing <|
credentials = cache.if_not_nothing <| cache "credentials"
Google_Analytics.list_dimensions property credentials . map f-> Option (f.api_name + " (" + f.category + ")") f.api_name.pretty
Google_Analytics.list_dimensions (credentials.if_nothing Google_Credential.Default) property . map f-> Option (f.api_name + " (" + f.category + ")") f.api_name.pretty
item_editor = make_single_choice (items.if_nothing ['country', 'year', 'month', 'date', 'userAgeBracket', 'userGender'])
Vector_Editor item_editor=item_editor item_default=item_editor.values.first.value display=..Always
Vector_Editor item_editor=item_editor item_default=item_editor.values.first.value display=display

## PRIVATE
private _make_start_date_widget -> Widget =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ type Google_Analytics_Account
to_display_text : Text
to_display_text self = "GA Account {" + self.name + " (" + self.id + ")}"

## ICON data_input
## GROUP Standard.Base.Metadata
ICON data_input
List of all properties of the account.

Arguments:
Expand All @@ -53,8 +54,8 @@ type Google_Analytics_Account
@credentials Google_Credential.default_widget
@limit Rows_To_Read.default_widget
properties : Google_Credential -> Rows_To_Read -> Boolean -> Vector
properties self credential:Google_Credential=..Default (limit : Rows_To_Read = ..First_With_Warning 1000) include_deleted:Boolean=False =
Google_Analytics.list_properties self credential limit include_deleted
properties self credentials:Google_Credential=..Default (limit : Rows_To_Read = ..First_With_Warning 1000) include_deleted:Boolean=False =
Google_Analytics.list_properties credentials self limit include_deleted

## Filter for Google Analytics accounts.
type Google_Analytics_Account_Filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,36 @@ type Google_Analytics_Property
to_display_text : Text
to_display_text self = self.to_text

## ICON data_input
## GROUP Standard.Base.Metadata
ICON data_input
List of all metrics of the property.

Arguments:
- credentials: The Google credentials to use. Default is the default
credentials.
@credentials (Google_Credential.default_widget)
metrics : Google_Credential -> Vector
metrics self credentials:Google_Credential=..Default =
Google_Analytics.list_metrics self credentials
Google_Analytics.list_metrics credentials self

## ICON data_input
## GROUP Standard.Base.Metadata
ICON data_input
List of all dimensions of the property.

Arguments:
- credentials: The Google credentials to use. Default is the default
credentials.
@credentials (Google_Credential.default_widget)
dimensions : Google_Credential -> Vector
dimensions self credentials:Google_Credential=..Default =
Google_Analytics.list_dimensions self credentials
Google_Analytics.list_dimensions credentials self

## PRIVATE
default_widget self_arg cache display:Display=..Always -> Widget =
_ = self_arg
Panic.catch Any handler=_->(Widget.Text_Input display=display) <|
credentials = cache.if_not_nothing <| cache "credentials"
options = Google_Analytics.list_properties account=..All_Accounts credentials=(credentials.if_nothing Google_Credential.Default) limit=(..First 10) . map p->(Option (p.name + " (" + p.id + ")") p.id.pretty)
options = Google_Analytics.list_properties credentials=(credentials.if_nothing Google_Credential.Default) account=..All_Accounts limit=(..First 10) . map p->(Option (p.name + " (" + p.id + ")") p.id.pretty)
make_single_choice options display=display

## PRIVATE
Expand Down
Loading

0 comments on commit d5f0e9e

Please sign in to comment.