I believe some calculation method exists that has as an input the light level (lx) and as output the ISO and exposure compensation values?
There are plenty of existing methods to set exposure parameters (ISO, exposure duration, and aperture) based on the amount of light received by a brightness sensor (usually called a light meter) in a camera.
Cameras with "Auto" exposure modes set all three parameters based on a hierarchy of prioritization used to produce a "best possible" image under the current shooting conditions.
- Lower ISO settings tend to result in a less "noisy" image
- Shorter exposure durations result in less blur due to camera or subject motion
- Narrower apertures allow deeper depth of field so that more of the scene is acceptable sharp and considered in focus
Unfortunately, to get all three of these things at what are usually considered optimal values, we need very bright light. We often need light that is much brighter than what we actually have with which to take a picture. Each of the three exposure parameters is weighed against the other two: how long can I expose before blur becomes noticeable? How wide can the aperture be opened before depth of field becomes too shallow? How much can I amplify the signal from the sensor before noise begins to noticeably degrade the image? Other factors, such as focal length (which affects the angular size of the field of view, and thus the amount of blur caused by a specific angular displacement of the camera during exposure) may also be considered.
For most phone cameras, aperture is fixed and not variable. That leaves duration (shutter time or shutter "speed", often abbreviated as Tv for 'time value') and ISO. In a digital environment 'ISO' really means "amplification" of the signal output by the imaging sensor, which only has one actual "sensitivity."
There are more than a few combinations of different Tv and ISO settings that will result in the same image brightness. If the light meter gives a brightness level suitable for a certain combination of aperture, Tv, and ISO, we can also expose for twice as long and amplify half as much, or we can expose for half as long and amplify twice as much and get the same image brightness. Each of those images will look different. If there is motion in the scene or the camera is moving during exposure, the longer Tv will show more movement. The shorter Tv will show less movement. But a shorter exposure at the same aperture means less light is actually being collected by the sensor, so we must amplify the signal from the sensor more by raising the ISO setting. This also amplifies the noise in the image.
But none of that above has to do with Exposure Compensation. It's strictly about Exposure, which assumes that the average brightness of the scene (or the average brightness of whatever portion of the scene is being metered) should be a medium value between pure black and pure white.
Exposure Compensation (EC) is a way of telling the camera to make the resulting photograph darker or lighter, on average over the total field of view (or whatever portion of the FoV that is being metered), than exactly halfway between pure black and pure white. We do not (usually) want a photo of a black cat in a coal mine to be the same brightness as a photo of a white cat in a snowstorm. We want one to be much darker than "medium bright". We want the other to be much brighter than "medium bright." The way this practically works out is that when we set an EC value, it calibrates the meter to center exposure a specific number of steps darker or brighter than the midtones halfway between totally dark and totally bright.
Many modern cameras can do a sort of internal EC when certain metering modes, such as 'Evaluative' (Canon) or 'Matrix' (Nikon) are selected. The light meter is divided into multiple segments and the brightness of each segment is measured independently. The resulting "map" of varying brightnesses is then compared to a library of different maps stored in the camera's memory. Each prestored map has a set of instructions on how to compensate exposure. The instructions for the stored map that is closest to the measured scene are used to adjust EC.
For example, a landscape scene with bright sky and darker land beneath it is very easily recognized by even the most rudimentary multi segment light meter. If the upper two thirds of the scene is very bright and the lower one-third is darker, the camera may be programmed to assume exposure should be set to capture details in the sky (such as very bright clouds) at the expense of allowing the lower one third of the scene to be grossly underexposed. If, on the other hand, the lower two-thirds of the frame are darker than the very bright upper one-third, the camera is probably programmed to expose for the darker areas at the expense of letting the sky be pure white and details in the bright sky will be lost.
In the past decade or so, dedicated light meters have advanced to the point that they now do multi segment metering in RGB+IR (red, green, blue, and near-infrared). They will even adjust EC based upon the specific colors in a scene compared to ever expanding libraries. Of course the most expensive camera models featured such RGB meters first, but now even many humble entry level cameras have RGB light meters. In the case of mirrorless cameras, metering is done directly off the RGB imaging sensor.
Many phones also use library based methods to compare with what the RGB image sensor in the camera is "seeing" and then take appropriate measures with regard to exposure. In darker light, the phone may even take multiple exposures and combine the results using auto alignment routines to increase the image quality of the final image.